view gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this8.C @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents 84e7813d76e9
children
line wrap: on
line source

// PR c++/56135
// { dg-do run { target c++11 } }

#include <functional>

struct test {
  template<typename T>
  std::function<void()> broken(int x) {
    return [=] { +x; print<T>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  std::function<void()> works0() {
    return [=] { print<int>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  template<typename T>
  std::function<void()> works1() {
    return [=] { print<int>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  template<typename T>
  std::function<void()> works2() {
    return [=] { this->print<T>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  template<typename T>
  void print() { if (this == 0) __builtin_abort (); }
};

int main(void) {
  test().broken<int>(1)();
  test().works0()();
  test().works1<int>()();
  test().works2<int>()();

  return 0;
}