gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const-neg.C
raw| 1 | // { dg-do compile { target c++11 } } |
| 2 | // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 3 | |
| 4 | #include <cassert> |
| 5 | |
| 6 | template<typename F> |
| 7 | void call(const F& f) { f(); } |
| 8 | |
| 9 | int main() { |
| 10 | call([] () -> void {}); |
| 11 | call([] () mutable -> void {}); |
| 12 | |
| 13 | int i = -1; |
| 14 | call([&i] () -> void { i = 0; }); |
| 15 | assert(i == 0); |
| 16 | call([i] () -> void { i = 0; }); // { dg-error "" "assignment to non-reference capture in const lambda" } |
| 17 | |
| 18 | return 0; |
| 19 | } |
| 20 |