Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/fail19965.d

raw
1 /*
2 REQUIRED_ARGS: -preview=dip1000
3 TEST_OUTPUT:
4 ---
5 fail_compilation/fail19965.d(36): Error: assigning address of variable `f` to `a` with longer lifetime is not allowed in a `@safe` function
6 ---
7 */
8
9 // https://issues.dlang.org/show_bug.cgi?id=19965
10
11 struct Buffer
12 {
13 int[10] data;
14
15 int[] getData() @safe return
16 {
17 return data[];
18 }
19 }
20
21 struct Foo()
22 {
23 Buffer buffer;
24
25 int[] toArray() @safe return
26 {
27 return buffer.getData;
28 }
29 }
30
31 int[] a;
32
33 void main() @safe
34 {
35 Foo!() f;
36 a = f.toArray;
37 }