Debian Codegraph @

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

raw
1 /* REQUIRED_ARGS: -preview=dip1000
2 TEST_OUTPUT:
3 ---
4 fail_compilation/test18484.d(19): Error: returning `x.bar()` escapes a reference to local variable `x`
5 fail_compilation/test18484.d(24): Error: escaping reference to stack allocated value returned by `S(0)`
6 ---
7 */
8
9 // https://issues.dlang.org/show_bug.cgi?id=18484
10
11 struct S
12 {
13 int* bar() @safe return;
14 int i;
15 }
16
17 int* test1() @safe
18 {
19 auto x = S(); return x.bar(); // error
20 }
21
22 int* test2() @safe
23 {
24 return S().bar(); // error
25 }