aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/test22298.d
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gdc.test/fail_compilation/test22298.d')
-rw-r--r--gcc/testsuite/gdc.test/fail_compilation/test22298.d30
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test22298.d b/gcc/testsuite/gdc.test/fail_compilation/test22298.d
new file mode 100644
index 0000000..cdb1a3e
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/test22298.d
@@ -0,0 +1,30 @@
+/*
+REQUIRED_ARGS: -preview=dip1000
+TEST_OUTPUT:
+---
+fail_compilation/test22298.d(18): Error: scope variable `i` assigned to `p` with longer lifetime
+fail_compilation/test22298.d(29): Error: scope variable `y` assigned to `x` with longer lifetime
+---
+*/
+
+void g(scope void delegate(scope int*) @safe cb) @safe {
+ int x = 42;
+ cb(&x);
+}
+
+void main() @safe {
+ int* p;
+ void f(scope int* i) @safe {
+ p = i;
+ }
+
+ g(&f);
+ // address of x has escaped g
+ assert(*p == 42);
+}
+
+void f() @safe {
+ mixin("scope int* x;");
+ scope int* y;
+ x = y;
+}