Debian Codegraph @

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

raw
1 /*
2 https://issues.dlang.org/show_bug.cgi?id=20068
3
4 TEST_OUTPUT:
5 ---
6 fail_compilation/union_initialization.d(19): Error: accessing overlapped field `B.p` with pointers is not allowed in a `@safe` function
7 fail_compilation/union_initialization.d(25): Error: accessing overlapped field `B.p` with pointers is not allowed in a `@safe` function
8 ---
9 */
10
11 union B
12 {
13 int i;
14 int* p;
15
16 @safe this(int* p)
17 {
18 this.p = p;
19 int* x = this.p;
20 }
21
22 @safe this(int** i)
23 {
24 this.p = null;
25 this.p = *i;
26 }
27 }
28
29 /*
30 TEST_OUTPUT:
31 ---
32 fail_compilation/union_initialization.d(109): Error: immutable field `p` initialized multiple times
33 fail_compilation/union_initialization.d(108): Previous initialization is here.
34 ---
35 */
36 #line 100
37
38 union C
39 {
40 int i;
41 immutable int* p;
42
43 @safe this(immutable int* p)
44 {
45 this.p = p;
46 this.p = null;
47 }
48 }
49
50 /*
51 https://issues.dlang.org/show_bug.cgi?id=21229
52
53 TEST_OUTPUT:
54 ---
55 fail_compilation/union_initialization.d(223): Error: field `union_` must be initialized in constructor
56 fail_compilation/union_initialization.d(223): Error: field `proxy` must be initialized in constructor
57 ---
58 */
59 #line 200
60
61 struct NeedsInit
62 {
63 int var;
64 long lo;
65 @disable this();
66 }
67
68 union Union
69 {
70 NeedsInit ni;
71 }
72
73 union Proxy
74 {
75 Union union_;
76 }
77
78 struct S
79 {
80 Union union_;
81 Proxy proxy;
82
83 this(int arg)
84 {
85 union_.ni.var = arg;
86 proxy.union_.ni.var = arg;
87 }
88 }