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