| 1 |
/* REQUIRED_ARGS: -preview=dip1000 |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/fix18575.d(27): Error: returning `s.foo()` escapes a reference to parameter `s` |
| 5 |
fail_compilation/fix18575.d(31): Error: returning `s.foo()` escapes a reference to parameter `s` |
| 6 |
fail_compilation/fix18575.d(35): Error: returning `s.abc()` escapes a reference to parameter `s` |
| 7 |
fail_compilation/fix18575.d(39): Error: returning `s.ghi(t)` escapes a reference to parameter `t` |
| 8 |
--- |
| 9 |
*/ |
| 10 |
|
| 11 |
// https://issues.dlang.org/show_bug.cgi?id=18575 |
| 12 |
|
| 13 |
@safe: |
| 14 |
|
| 15 |
struct S { |
| 16 |
@safe: |
| 17 |
int x; |
| 18 |
|
| 19 |
void bar() { } |
| 20 |
auto foo() { return &this.bar; } |
| 21 |
auto def() { return &bar; } |
| 22 |
auto abc() { return &x; } |
| 23 |
auto ghi(ref S s) { return &s.bar; } |
| 24 |
} |
| 25 |
|
| 26 |
auto f(S s) { |
| 27 |
return s.foo(); |
| 28 |
} |
| 29 |
|
| 30 |
auto g(S s) { |
| 31 |
return s.foo(); |
| 32 |
} |
| 33 |
|
| 34 |
auto h(S s) { |
| 35 |
return s.abc(); |
| 36 |
} |
| 37 |
|
| 38 |
auto j(S s, S t) { |
| 39 |
return s.ghi(t); |
| 40 |
} |