| 1 |
// PR c++/56135 |
| 2 |
// { dg-do run { target c++11 } } |
| 3 |
// { dg-skip-if "requires hosted libstdc++ for functional function" { ! hostedlib } } |
| 4 |
|
| 5 |
#include <functional> |
| 6 |
|
| 7 |
struct test { |
| 8 |
template<typename T> |
| 9 |
std::function<void()> broken(int x) { |
| 10 |
return [=] { +x; print<T>(); }; // { dg-warning "implicit capture" "" { target c++2a } } |
| 11 |
} |
| 12 |
|
| 13 |
std::function<void()> works0() { |
| 14 |
return [=] { print<int>(); }; // { dg-warning "implicit capture" "" { target c++2a } } |
| 15 |
} |
| 16 |
|
| 17 |
template<typename T> |
| 18 |
std::function<void()> works1() { |
| 19 |
return [=] { print<int>(); }; // { dg-warning "implicit capture" "" { target c++2a } } |
| 20 |
} |
| 21 |
|
| 22 |
template<typename T> |
| 23 |
std::function<void()> works2() { |
| 24 |
return [=] { this->print<T>(); }; // { dg-warning "implicit capture" "" { target c++2a } } |
| 25 |
} |
| 26 |
|
| 27 |
template<typename T> |
| 28 |
void print() { if (this == 0) __builtin_abort (); } |
| 29 |
}; |
| 30 |
|
| 31 |
int main(void) { |
| 32 |
test().broken<int>(1)(); |
| 33 |
test().works0()(); |
| 34 |
test().works1<int>()(); |
| 35 |
test().works2<int>()(); |
| 36 |
|
| 37 |
return 0; |
| 38 |
} |