| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 3 |
|
| 4 |
#include <cassert> |
| 5 |
|
| 6 |
struct A { |
| 7 |
int i; |
| 8 |
A(): i(42) { } |
| 9 |
int f() { |
| 10 |
return [this]{ |
| 11 |
return [=]{ return i; }(); // { dg-warning "implicit capture" "" { target c++2a } } |
| 12 |
}(); |
| 13 |
} |
| 14 |
}; |
| 15 |
|
| 16 |
int main() { |
| 17 |
int i = 1; |
| 18 |
|
| 19 |
[] (int& i) -> void { |
| 20 |
[&] () -> void { |
| 21 |
i = 2; |
| 22 |
} (); |
| 23 |
} (i); |
| 24 |
|
| 25 |
assert(i == 2); |
| 26 |
|
| 27 |
[&] () -> void { |
| 28 |
[&i] () -> void { |
| 29 |
i = 3; |
| 30 |
} (); |
| 31 |
} (); |
| 32 |
|
| 33 |
assert(i == 3); |
| 34 |
|
| 35 |
[&] () -> void { |
| 36 |
[&] () -> void { |
| 37 |
i = 4; |
| 38 |
} (); |
| 39 |
} (); |
| 40 |
|
| 41 |
assert(i == 4); |
| 42 |
i = 4; |
| 43 |
|
| 44 |
[&] () -> void { |
| 45 |
[=] () mutable -> void { |
| 46 |
i = 5; |
| 47 |
} (); |
| 48 |
} (); |
| 49 |
|
| 50 |
assert(i == 4); |
| 51 |
|
| 52 |
[=] () mutable -> void { |
| 53 |
[&] () -> void { |
| 54 |
i = 6; |
| 55 |
} (); |
| 56 |
} (); |
| 57 |
|
| 58 |
assert(i == 4); |
| 59 |
|
| 60 |
assert (A().f() == 42); |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |