gcc/testsuite/gdc.test/fail_compilation/fail22118.d
raw| 1 | // https://issues.dlang.org/show_bug.cgi?id=22118 |
| 2 | |
| 3 | /* |
| 4 | TEST_OUTPUT: |
| 5 | --- |
| 6 | fail_compilation/fail22118.d(33): Error: cannot modify `this.v.a` in `const` function |
| 7 | --- |
| 8 | */ |
| 9 | |
| 10 | struct NeedsInit |
| 11 | { |
| 12 | int n; |
| 13 | @disable this(); |
| 14 | } |
| 15 | |
| 16 | union U |
| 17 | { |
| 18 | NeedsInit a; |
| 19 | } |
| 20 | |
| 21 | struct V |
| 22 | { |
| 23 | NeedsInit a; |
| 24 | } |
| 25 | |
| 26 | struct S |
| 27 | { |
| 28 | U u; |
| 29 | V v; |
| 30 | this(const NeedsInit arg) const |
| 31 | { |
| 32 | u.a = arg; // this should compile |
| 33 | v.a = arg; // this should not |
| 34 | } |
| 35 | } |