| 1 |
// https://issues.dlang.org/show_bug.cgi?id=24157 |
| 2 |
|
| 3 |
/* |
| 4 |
TEST_OUTPUT: |
| 5 |
--- |
| 6 |
fail_compilation/test24157.d(23): Error: cannot take address of expression `p.self()` because it is not an lvalue |
| 7 |
fail_compilation/test24157.d(27): Error: cannot take address of expression `p.unshared()` because it is not an lvalue |
| 8 |
--- |
| 9 |
*/ |
| 10 |
|
| 11 |
class Promise { |
| 12 |
auto ref self() { |
| 13 |
return this; |
| 14 |
} |
| 15 |
|
| 16 |
auto ref unshared() shared { |
| 17 |
return cast() this; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
void testThis(Promise p) { |
| 23 |
auto ptr = &p.self(); // must not return a ref to the Promise class ref |
| 24 |
} |
| 25 |
|
| 26 |
void testCastThis(shared Promise p) { |
| 27 |
auto ptr = &p.unshared(); // ditto |
| 28 |
} |