| 1 |
/* |
| 2 |
REQUIRED_ARGS: -preview=dip1000 |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/test16589.d(26): Error: escaping a reference to parameter `this` by returning `&this.data` is not allowed in a `@safe` function |
| 6 |
fail_compilation/test16589.d(24): perhaps annotate the function with `return` |
| 7 |
fail_compilation/test16589.d(31): Error: escaping a reference to parameter `this` by returning `&this` is not allowed in a `@safe` function |
| 8 |
fail_compilation/test16589.d(29): perhaps annotate the function with `return` |
| 9 |
fail_compilation/test16589.d(37): Error: escaping a reference to parameter `s` by returning `&s.data` is not allowed in a `@safe` function |
| 10 |
fail_compilation/test16589.d(35): perhaps annotate the parameter with `return` |
| 11 |
fail_compilation/test16589.d(42): Error: escaping a reference to parameter `s` by returning `&s` is not allowed in a `@safe` function |
| 12 |
fail_compilation/test16589.d(40): perhaps annotate the parameter with `return` |
| 13 |
fail_compilation/test16589.d(47): Error: returning `&s.data` escapes a reference to parameter `s` |
| 14 |
fail_compilation/test16589.d(52): Error: returning `& s` escapes a reference to parameter `s` |
| 15 |
--- |
| 16 |
*/ |
| 17 |
|
| 18 |
// https://issues.dlang.org/show_bug.cgi?id=16589 |
| 19 |
|
| 20 |
struct S |
| 21 |
{ |
| 22 |
int data; |
| 23 |
|
| 24 |
@safe int* access1() |
| 25 |
{ |
| 26 |
return &data; |
| 27 |
} |
| 28 |
|
| 29 |
@safe S* access2() |
| 30 |
{ |
| 31 |
return &this; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
@safe int* access3(ref S s) |
| 36 |
{ |
| 37 |
return &s.data; |
| 38 |
} |
| 39 |
|
| 40 |
@safe S* access4(ref S s) |
| 41 |
{ |
| 42 |
return &s; |
| 43 |
} |
| 44 |
|
| 45 |
@safe int* access5(S s) |
| 46 |
{ |
| 47 |
return &s.data; |
| 48 |
} |
| 49 |
|
| 50 |
@safe S* access6(S s) |
| 51 |
{ |
| 52 |
return &s; |
| 53 |
} |
| 54 |
|
| 55 |
class C |
| 56 |
{ |
| 57 |
int data; |
| 58 |
|
| 59 |
@safe int* access7() |
| 60 |
{ |
| 61 |
return &data; |
| 62 |
} |
| 63 |
} |