gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable.C
raw| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 3 | #include <cassert> |
| 4 | |
| 5 | int main() { |
| 6 | int i = 1; |
| 7 | const char* s1 = "hello"; |
| 8 | const char* s2 = s1; |
| 9 | [i, s2] () mutable -> void { i = 2; s2 = "world"; } (); |
| 10 | //[i, s2] () -> void { i = 2; s2 = "world"; } (); // { dg-error: "assignment of data-member in read-only structure" } |
| 11 | assert(i == 1); |
| 12 | assert(s1 == s2); |
| 13 | |
| 14 | return 0; |
| 15 | } |
| 16 |