summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable.C')
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable.C16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable.C
new file mode 100644
index 000000000..73a4d1bac
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable.C
@@ -0,0 +1,16 @@
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+#include <cassert>
+
+int main() {
+ int i = 1;
+ const char* s1 = "hello";
+ const char* s2 = s1;
+ [i, s2] () mutable -> void { i = 2; s2 = "world"; } ();
+ //[i, s2] () -> void { i = 2; s2 = "world"; } (); // { dg-error: "assignment of data-member in read-only structure" }
+ assert(i == 1);
+ assert(s1 == s2);
+
+ return 0;
+}
+