| 1 |
/* |
| 2 |
REQUIRED_ARGS: -preview=dip1000 |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/test20881.d(20): Error: returning scope variable `this` is not allowed in a `@safe` function |
| 6 |
fail_compilation/test20881.d(27): Error: assigning address of variable `s` to `global` with longer lifetime is not allowed in a `@safe` function |
| 7 |
fail_compilation/test20881.d(28): Error: assigning address of variable `s` to `global` with longer lifetime is not allowed in a `@safe` function |
| 8 |
fail_compilation/test20881.d(29): Error: assigning address of variable `s` to `global` with longer lifetime is not allowed in a `@safe` function |
| 9 |
--- |
| 10 |
*/ |
| 11 |
@safe: |
| 12 |
|
| 13 |
// https://issues.dlang.org/show_bug.cgi?id=20881 |
| 14 |
struct S |
| 15 |
{ |
| 16 |
int* ptr; |
| 17 |
|
| 18 |
auto borrowA() return /*scope inferred*/ { return ptr; } |
| 19 |
int* borrowB() return { return ptr; } |
| 20 |
int* borrowC() scope return { return ptr; } |
| 21 |
} |
| 22 |
|
| 23 |
void main() |
| 24 |
{ |
| 25 |
static int* global; |
| 26 |
S s; |
| 27 |
global = s.borrowA; |
| 28 |
global = s.borrowB; |
| 29 |
global = s.borrowC; |
| 30 |
} |