dmd/compiler/test/fail_compilation/test18484.d
2022-07-09 18:53:07 +02:00

25 lines
495 B
D

/* REQUIRED_ARGS: -preview=dip1000
TEST_OUTPUT:
---
fail_compilation/test18484.d(19): Error: returning `x.bar()` escapes a reference to local variable `x`
fail_compilation/test18484.d(24): Error: escaping reference to stack allocated value returned by `S(0)`
---
*/
// https://issues.dlang.org/show_bug.cgi?id=18484
struct S
{
int* bar() @safe return;
int i;
}
int* test1() @safe
{
auto x = S(); return x.bar(); // error
}
int* test2() @safe
{
return S().bar(); // error
}