gcc/testsuite/gdc.test/runnable/bug16146.d
raw| 1 | struct X { |
| 2 | int* rc; |
| 3 | this (int n) { auto x = new int[](1); rc = x.ptr; *rc = n; } |
| 4 | this (this) { ++*rc; } |
| 5 | ~this () { --*rc; } |
| 6 | @disable void opAssign (X src); |
| 7 | } |
| 8 | |
| 9 | struct Y { |
| 10 | X x; |
| 11 | } |
| 12 | |
| 13 | void frob(X x) |
| 14 | { |
| 15 | Y y = { x: x }; |
| 16 | // The 'rc' counter starts from 1 and gets bumped when: |
| 17 | // - 'f0' is passed to 'frob' |
| 18 | // - 'y' is initialized with 'x' |
| 19 | assert(*y.x.rc == 3); |
| 20 | } |
| 21 | |
| 22 | void main () |
| 23 | { |
| 24 | auto f0 = X(1); |
| 25 | frob(f0); |
| 26 | } |