gcc/testsuite/gdc.test/runnable/test19774.d
raw| 1 | // https://issues.dlang.org/show_bug.cgi?id=19774 |
| 2 | C bar() |
| 3 | { |
| 4 | return C(42); |
| 5 | } |
| 6 | |
| 7 | C foo() |
| 8 | { |
| 9 | return bar()[1]; |
| 10 | } |
| 11 | |
| 12 | C gun() |
| 13 | { |
| 14 | return bar()[$]; |
| 15 | } |
| 16 | |
| 17 | struct C |
| 18 | { |
| 19 | int x; |
| 20 | |
| 21 | ~this() |
| 22 | { |
| 23 | x = 0; |
| 24 | } |
| 25 | |
| 26 | int opDollar() |
| 27 | { |
| 28 | return 1; |
| 29 | } |
| 30 | |
| 31 | C opIndex(int a) |
| 32 | { |
| 33 | return this; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void main() |
| 38 | { |
| 39 | auto c = foo(); |
| 40 | assert(c.x == 42); /* fails; should pass */ |
| 41 | auto d = gun(); |
| 42 | assert(d.x == 42); |
| 43 | } |