| 1 |
/* |
| 2 |
REQUIRED_ARGS: |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/test20809.d(114): Error: escaping a reference to parameter `this` by returning `this.a` is not allowed in a `@safe` function |
| 6 |
fail_compilation/test20809.d(112): perhaps annotate the function with `return` |
| 7 |
--- |
| 8 |
*/ |
| 9 |
|
| 10 |
// https://issues.dlang.org/show_bug.cgi?id=20809 |
| 11 |
|
| 12 |
#line 100 |
| 13 |
|
| 14 |
@safe: |
| 15 |
|
| 16 |
struct S |
| 17 |
{ |
| 18 |
@safe: |
| 19 |
int a; |
| 20 |
~this() |
| 21 |
{ |
| 22 |
a = 0; |
| 23 |
} |
| 24 |
|
| 25 |
ref int val() |
| 26 |
{ |
| 27 |
return a; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
S bar() |
| 32 |
{ |
| 33 |
return S(2); |
| 34 |
} |
| 35 |
|
| 36 |
int foo() |
| 37 |
{ |
| 38 |
return bar.val; |
| 39 |
} |
| 40 |
|
| 41 |
void test() |
| 42 |
{ |
| 43 |
assert(foo() == 2); |
| 44 |
} |