| 1 |
/* |
| 2 |
REQUIRED_ARGS: -preview=dip1000 |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/test22298.d(18): Error: assigning scope variable `i` to `p` with longer lifetime is not allowed in a `@safe` function |
| 6 |
fail_compilation/test22298.d(29): Error: assigning scope variable `y` to `x` with longer lifetime is not allowed in a `@safe` function |
| 7 |
--- |
| 8 |
*/ |
| 9 |
|
| 10 |
void g(scope void delegate(scope int*) @safe cb) @safe { |
| 11 |
int x = 42; |
| 12 |
cb(&x); |
| 13 |
} |
| 14 |
|
| 15 |
void main() @safe { |
| 16 |
int* p; |
| 17 |
void f(scope int* i) @safe { |
| 18 |
p = i; |
| 19 |
} |
| 20 |
|
| 21 |
g(&f); |
| 22 |
// address of x has escaped g |
| 23 |
assert(*p == 42); |
| 24 |
} |
| 25 |
|
| 26 |
void f() @safe { |
| 27 |
mixin("scope int* x;"); |
| 28 |
scope int* y; |
| 29 |
x = y; |
| 30 |
} |