| 1 |
// REQUIRED_ARGS: -preview=dip1000 |
| 2 |
/* |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/fail20108.d(15): Error: assigning address of variable `y` to `x` with longer lifetime is not allowed in a `@safe` function |
| 6 |
fail_compilation/fail20108.d(16): Error: scope parameter `x` may not be returned |
| 7 |
fail_compilation/fail20108.d(23): Error: assigning address of variable `y` to `x` with longer lifetime is not allowed in a `@safe` function |
| 8 |
fail_compilation/fail20108.d(24): Error: returning scope variable `x` is not allowed in a `@safe` function |
| 9 |
--- |
| 10 |
*/ |
| 11 |
|
| 12 |
@safe auto test(scope int* x) |
| 13 |
{ |
| 14 |
int y = 69; |
| 15 |
x = &y; //bad |
| 16 |
return x; |
| 17 |
} |
| 18 |
|
| 19 |
@safe auto test2() |
| 20 |
{ |
| 21 |
scope int* x; |
| 22 |
int y = 69; |
| 23 |
x = &y; //bad |
| 24 |
return x; |
| 25 |
} |
| 26 |
|
| 27 |
void main() |
| 28 |
{ |
| 29 |
auto y = test(null); |
| 30 |
auto z = test2(); |
| 31 |
} |