2 REQUIRED_ARGS: -preview=dip1000
4 fail_compilation/test15191.d(34): Error: returning `&identity(x)` escapes a reference to local variable `x`
5 fail_compilation/test15191.d(40): Error: returning `&identityPtr(x)` escapes a reference to local variable `x`
6 fail_compilation/test15191.d(46): Error: returning `&identityPtr(x)` escapes a reference to local variable `x`
7 fail_compilation/test15191.d(67): Error: cannot take address of `scope` variable `x` since `scope` applies to first indirection only
8 fail_compilation/test15191.d(69): Error: cannot take address of `scope` variable `x` since `scope` applies to first indirection only
12 // Test taking the address of a `ref return` using & and [] operators
13 // https://issues.dlang.org/show_bug.cgi?id=15191
14 // https://issues.dlang.org/show_bug.cgi?id=22519
15 // https://issues.dlang.org/show_bug.cgi?id=22539
18 ref int foo(return ref int s
)
23 int* bar(return ref int s
)
28 ref int identity(ref return int x
) {return x
;}
29 ref int* identityPtr(ref return int* x
) {return x
;}
31 int* addrOfRefEscape()
37 int** addrOfRefSystem() @system
40 return &identityPtr(x
);
43 int** addrOfRefTransitive()
46 return &identityPtr(x
);
50 ref int getGlobalInt() {return gInt
;}
52 int* addrOfRefGlobal()
54 return &getGlobalInt();
58 ref int*[1] identityArr(return ref scope int*[1] x
)
63 int*[] sliceOfRefEscape()
66 scope int*[1] x
= [&stackVar
];
67 auto y
= identityArr(x
)[]; // check transitive scope in assignment
69 return identityArr(x
)[]; // check transitive scope in return statement
72 // https://issues.dlang.org/show_bug.cgi?id=23079