Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/fail18719.d

raw
1 // https://issues.dlang.org/show_bug.cgi?id=18719
2
3 /*
4 TEST_OUTPUT:
5 ---
6 fail_compilation/fail18719.d(29): Error: immutable field `x` initialized multiple times
7 Previous initialization is here.
8 ---
9 */
10
11 struct S
12 {
13 int x = -1;
14 this(int y) immutable
15 {
16 x = y;
17 import core.stdc.stdio;
18 printf("Ctor called with %d\n", y);
19 }
20 void opAssign(int) immutable;
21 }
22
23 class C
24 {
25 S x;
26 this() immutable
27 {
28 this(42); /* Initializes x. */
29 x = 13; /* Breaking immutable, or ok? */
30 }
31 this(int x) immutable
32 {
33 this.x = x;
34 }
35 }
36
37 void main()
38 {
39 new immutable C;
40 }