summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/test19097.d
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gdc.test/fail_compilation/test19097.d')
-rw-r--r--gcc/testsuite/gdc.test/fail_compilation/test19097.d64
1 files changed, 59 insertions, 5 deletions
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test19097.d b/gcc/testsuite/gdc.test/fail_compilation/test19097.d
index 034813b5316..9c025a83ff0 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/test19097.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/test19097.d
@@ -1,12 +1,19 @@
/* REQUIRED_ARGS: -preview=dip1000
* TEST_OUTPUT:
---
-fail_compilation/test19097.d(37): Error: scope variable `s` may not be returned
-fail_compilation/test19097.d(66): Error: scope variable `z` assigned to `refPtr` with longer lifetime
-fail_compilation/test19097.d(97): Error: scope variable `s` may not be returned
+fail_compilation/test19097.d(44): Error: scope variable `s` may not be returned
+fail_compilation/test19097.d(48): Error: scope variable `s1` may not be returned
+fail_compilation/test19097.d(77): Error: scope variable `z` assigned to `refPtr` with longer lifetime
+fail_compilation/test19097.d(108): Error: scope variable `s4` may not be returned
+fail_compilation/test19097.d(126): Error: scope variable `s5c` may not be returned
+fail_compilation/test19097.d(130): Error: scope variable `s5m` may not be returned
+fail_compilation/test19097.d(147): Error: scope variable `s6c` may not be returned
+fail_compilation/test19097.d(151): Error: scope variable `s6m` may not be returned
---
*/
+// Test extended return-scope / return-ref semantics, e.g. assigning to `this` or the first parameter
+
// https://issues.dlang.org/show_bug.cgi?id=19097
@safe:
@@ -35,6 +42,10 @@ S thorin()
int i;
S s = S(&i); // should infer scope for s
return s; // so this should error
+
+ S s1;
+ s1.mem(&i);
+ return s1;
}
/************************/
@@ -93,6 +104,49 @@ struct S4
int* escape2()
{
int x;
- auto s = S4(0, &x);
- return s.p;
+ auto s4 = S4(0, &x);
+ return s4.p;
+}
+
+/************************/
+// https://issues.dlang.org/show_bug.cgi?id=22801
+struct S5
+{
+ int* a;
+ this(return ref int b) { a = &b; }
+
+ int* c;
+ void mem(return ref int d) scope { c = &d; }
+}
+
+S5 frerin()
+{
+ int i;
+ S5 s5c = S5(i); // should infer scope for s
+ return s5c; // so this should error
+
+ S5 s5m;
+ s5m.mem(i);
+ return s5m;
+}
+
+
+struct S6
+{
+ int** a;
+ this(return ref int* b) { a = &b; }
+
+ int** c;
+ void mem(return ref int* d) scope { c = &d; }
+}
+
+S6 dis()
+{
+ int* i = null;
+ S6 s6c = S6(i); // should infer scope for s
+ return s6c; // so this should error
+
+ S6 s6m;
+ s6m.mem(i);
+ return s6m;
}