Debian Codegraph @

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

raw
1 /***************************************************/
2 // with disable this() struct
3
4 struct X
5 {
6 @disable this();
7
8 this(int) {}
9 }
10
11 /+
12 TEST_OUTPUT:
13 ---
14 fail_compilation/fail9665b.d(32): Error: one path skips field `x2`
15 fail_compilation/fail9665b.d(33): Error: one path skips field `x3`
16 fail_compilation/fail9665b.d(35): Error: one path skips field `x5`
17 fail_compilation/fail9665b.d(36): Error: one path skips field `x6`
18 fail_compilation/fail9665b.d(30): Error: field `x1` must be initialized in constructor
19 fail_compilation/fail9665b.d(30): Error: field `x4` must be initialized in constructor
20 ---
21 +/
22 struct S1
23 {
24 X x1;
25 X x2;
26 X x3;
27 X[2] x4;
28 X[2] x5;
29 X[2] x6;
30 this(int)
31 {
32 if (true) x2 = X(1);
33 auto n = true ? (x3 = X(1)) : X.init;
34
35 if (true) x5 = X(1);
36 auto m = true ? (x6 = X(1)) : typeof(x6).init;
37 }
38 }
39
40 /***************************************************/
41 // with nested struct
42
43 /+
44 TEST_OUTPUT:
45 ---
46 fail_compilation/fail9665b.d(65): Error: one path skips field `x2`
47 fail_compilation/fail9665b.d(66): Error: one path skips field `x3`
48 fail_compilation/fail9665b.d(68): Error: one path skips field `x5`
49 fail_compilation/fail9665b.d(69): Error: one path skips field `x6`
50 fail_compilation/fail9665b.d(63): Error: field `x1` must be initialized in constructor, because it is nested struct
51 fail_compilation/fail9665b.d(63): Error: field `x4` must be initialized in constructor, because it is nested struct
52 fail_compilation/fail9665b.d(76): Error: template instance `fail9665b.S2!(X)` error instantiating
53 ---
54 +/
55 struct S2(X)
56 {
57 X x1;
58 X x2;
59 X x3;
60 X[2] x4;
61 X[2] x5;
62 X[2] x6;
63 this(X x)
64 {
65 if (true) x2 = x;
66 auto a = true ? (x3 = x) : X.init;
67
68 if (true) x5 = x;
69 auto b = true ? (x6 = x) : typeof(x6).init;
70 }
71 }
72 void test2()
73 {
74 struct X { this(int) {} }
75 static assert(X.tupleof.length == 1);
76 S2!(X) s = X(1);
77 }