1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// PR c++/92812
// { dg-do run { target c++20 } }
// { dg-options "-Wall -Wextra" }
// Initializing arrays in a member init list using ()-init, valid cases.
#define assert(X) do { if (!(X)) __builtin_abort(); } while(0)
struct S { int x, y; };
struct N { int x, y; N(int, int); };
static S s{10, 11};
struct A {
S s1;
S s2;
S a1[2];
S a2[2];
S a3[2];
S a4[2];
S a5[2];
S a6[2];
A() : s1(1, 2),
s2(1), // { dg-warning "missing initializer for member" }
a1({1}), // { dg-warning "missing initializer for member" }
a2({1, 2}),
a3({}, {}),
a4(),
a5(s),
a6(s, s)
{ }
};
struct C {
int a1[2];
int a2[2];
int a3[2];
int a4[2];
int a5[2];
C() : a1(1),
a2(1, 2),
a3({1}),
a4({}, {}),
a5()
{ }
};
struct D {
N n;
// Not an aggregate, should work pre-C++20 too.
D() : n(1, 2) { }
};
struct E {
char a1[4];
char a2[4];
E() : a1("ab"),
a2("abc")
{ }
};
// Compound literal.
struct F {
F ();
S m[1];
};
F::F () : m(__extension__(S[1]) { 1, 2 })
{
}
struct B { int i; };
struct Der : B { };
Der d;
struct G {
B b1[1];
B b2[2];
G(): b1(d),
b2(d, d)
{ }
};
// Variation of c++/93790.
struct Empty { };
struct Empty_refwrap {
Empty& r;
Empty_refwrap(Empty &e) : r(e) { }
operator Empty&() { return r; }
};
Empty empty;
Empty_refwrap empty_refwrap(empty);
struct H {
Empty &e;
// Turning this into {empty_refwrap} would break things.
H() : e(empty_refwrap) { }
};
int
main ()
{
A a;
assert (a.s1.x == 1 && a.s1.y == 2);
assert (a.s2.x == 1 && a.s2.y == 0);
assert (a.a1[0].x == 1 && a.a1[0].y == 0
&& a.a1[1].x == 0 && a.a1[1].y == 0);
assert (a.a2[0].x == 1 && a.a2[0].y == 2
&& a.a2[1].x == 0 && a.a2[1].y == 0);
assert (a.a3[0].x == 0 && a.a3[0].y == 0
&& a.a3[1].x == 0 && a.a3[1].y == 0);
assert (a.a4[0].x == 0 && a.a4[0].y == 0
&& a.a4[1].x == 0 && a.a4[1].y == 0);
assert (a.a5[0].x == 10 && a.a5[0].y == 11
&& a.a5[1].x == 0 && a.a5[1].y == 0);
assert (a.a6[0].x == 10 && a.a6[0].y == 11
&& a.a6[1].x == 10 && a.a6[1].y == 11);
C c;
assert (c.a1[0] == 1 && c.a1[1] == 0);
assert (c.a2[0] == 1 && c.a2[1] == 2);
assert (c.a3[0] == 1 && c.a3[1] == 0);
assert (c.a4[0] == 0 && c.a4[1] == 0);
assert (c.a5[0] == 0 && c.a5[1] == 0);
E e;
assert (__builtin_strcmp (e.a1, "ab") == 0
&& __builtin_strcmp (e.a2, "abc") == 0);
}
|