| 1 |
// PR c++/91363 - P0960R3: Parenthesized initialization of aggregates. |
| 2 |
// { dg-do run { target c++20 } } |
| 3 |
|
| 4 |
struct A { |
| 5 |
int i; |
| 6 |
int j; |
| 7 |
int k; |
| 8 |
}; |
| 9 |
|
| 10 |
struct B { |
| 11 |
int i; |
| 12 |
int j; |
| 13 |
int k = 42; |
| 14 |
}; |
| 15 |
|
| 16 |
struct C { |
| 17 |
A a; |
| 18 |
}; |
| 19 |
|
| 20 |
struct D { |
| 21 |
A a1; |
| 22 |
A a2; |
| 23 |
}; |
| 24 |
|
| 25 |
struct E { |
| 26 |
int i; |
| 27 |
}; |
| 28 |
|
| 29 |
// F has a base class, but it's not virtual, private, or protected, so this is |
| 30 |
// still an aggregate (since C++17). |
| 31 |
struct F : E { |
| 32 |
int j; |
| 33 |
int k; |
| 34 |
}; |
| 35 |
|
| 36 |
F f({1}, 2, 3); |
| 37 |
|
| 38 |
// A non-virtual member function doesn't make it a non-aggregate. |
| 39 |
struct G { |
| 40 |
int i; |
| 41 |
double j; |
| 42 |
int foo(int, int); |
| 43 |
}; |
| 44 |
|
| 45 |
G g(1, 2.14); |
| 46 |
|
| 47 |
class H { |
| 48 |
public: |
| 49 |
H (int) { } |
| 50 |
}; |
| 51 |
|
| 52 |
class I : public H { }; |
| 53 |
|
| 54 |
int i; |
| 55 |
A a1(1, 2); |
| 56 |
A a2(1.0, 2); |
| 57 |
A a3(++i, ++i); |
| 58 |
const A& ra(1, 2); |
| 59 |
|
| 60 |
A ca = A(1, 2); |
| 61 |
A ca2 = A(1.0, 2); |
| 62 |
A ca3 = A(++i, ++i); |
| 63 |
const A& rca = A(1, 2); |
| 64 |
|
| 65 |
B b1(1, 2, 3); |
| 66 |
B b2(1, 2); |
| 67 |
B b3(1); |
| 68 |
|
| 69 |
C c1({5, 6, 7}); |
| 70 |
D d1({1, 2, 3}, {5, 6, 7}); |
| 71 |
|
| 72 |
struct W { |
| 73 |
const char *s, *t; |
| 74 |
}; |
| 75 |
W w1("fluffer", "nutter"); |
| 76 |
|
| 77 |
struct Y { |
| 78 |
char a[4]; |
| 79 |
}; |
| 80 |
Y y("yew"); |
| 81 |
|
| 82 |
int |
| 83 |
main () |
| 84 |
{ |
| 85 |
I(10); |
| 86 |
|
| 87 |
// A::k will be value-initialized. |
| 88 |
if (a1.i != 1 || a1.j != 2 || a1.k != 0) |
| 89 |
__builtin_abort (); |
| 90 |
if (a2.i != 1 || a2.j != 2 || a2.k != 0) |
| 91 |
__builtin_abort (); |
| 92 |
if (a3.i != 1 || a3.j != 2 || a3.k != 0) |
| 93 |
__builtin_abort (); |
| 94 |
if (ra.i != 1 || ra.j != 2 || ra.k != 0) |
| 95 |
__builtin_abort (); |
| 96 |
if (ca.i != 1 || ca.j != 2 || ca.k != 0) |
| 97 |
__builtin_abort (); |
| 98 |
if (ca2.i != 1 || ca2.j != 2 || ca2.k != 0) |
| 99 |
__builtin_abort (); |
| 100 |
if (ca3.i != 3 || ca3.j != 4 || ca3.k != 0) |
| 101 |
__builtin_abort (); |
| 102 |
|
| 103 |
if (b1.i != 1 || b1.j != 2 || b1.k != 3) |
| 104 |
__builtin_abort (); |
| 105 |
// The default member initializer will be used for B::k. |
| 106 |
if (b2.i != 1 || b2.j != 2 || b2.k != 42) |
| 107 |
__builtin_abort (); |
| 108 |
if (b3.i != 1 || b3.j != 0 || b3.k != 42) |
| 109 |
__builtin_abort (); |
| 110 |
|
| 111 |
if (c1.a.i != 5 || c1.a.j != 6 || c1.a.k != 7) |
| 112 |
__builtin_abort (); |
| 113 |
|
| 114 |
if (f.i != 1 || f.j != 2 || f.k != 3) |
| 115 |
__builtin_abort (); |
| 116 |
} |