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
|
// PR c++/91363 - P0960R3: Parenthesized initialization of aggregates.
// { dg-do compile { target c++20 } }
// Test ill-formed code.
// If k is greater than the size of the array, the program is ill-formed.
int a1[2](1, 2, 3); // { dg-error "too many initializers" }
int a2[](); // { dg-error "array of functions" }
int a3[](()); // { dg-error "expected primary-expression" }
int a4[]("raccoon"); // { dg-error "invalid conversion" }
struct S {
int i;
int j;
};
S s1(1, 1, 1); // { dg-error "too many initializers" }
union U2 {
int a;
float b;
};
// [dcl.init.aggr]/19:
// When a union is initialized with an initializer list, there shall not be
// more than one explicitly initialized element.
U2 u4 = U2(1, 2); // { dg-error "too many initializers" }
// Test there is no brace elision.
int a[2][2](1, 2, 3, 4); // { dg-error "too many initializers|array must be initialized with a brace-enclosed initializer" }
// private/protected/virtual base class -> not an aggregate.
struct B { };
struct D : private B {
int i;
int j;
};
D d({}, 1, 2); // { dg-error "no matching function" }
// Private non-static data member -> not an aggregate.
struct P {
int i;
private:
int j;
};
P p(1, 2); // { dg-error "no matching function" }
// User-declared constructor -> not an aggregate.
struct U {
U() {}
int i;
int j;
};
U u(1, 2); // { dg-error "no matching function" }
// virtual member function -> not an aggregate.
struct V {
int i;
int j;
virtual int foo(int);
};
V v(1, 2); // { dg-error "no matching function" }
struct nonaggr {
int i;
int j;
private:
int x;
};
struct F {
nonaggr n;
F() : n(1) { } // { dg-error "no matching function" }
};
struct G {
char a[4];
};
struct H {
G g;
H() : g("oaks") { } // { dg-error "initializer-string" }
};
|