| 1 |
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify=expected,cxx17 -std=c++17 %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify=expected,cxx20 -std=c++2a %s |
| 3 |
|
| 4 |
// cxx17-warning@* 0+{{designated initializers are a C++20 extension}} |
| 5 |
|
| 6 |
void f1(int i[static 5]) { // expected-error{{C99}} |
| 7 |
} |
| 8 |
|
| 9 |
struct Point { int x; int y; int z[]; }; // expected-warning{{flexible array members are a C99 feature}} |
| 10 |
|
| 11 |
Point p1 = { .x = 17, |
| 12 |
y: 25 }; // expected-warning{{use of GNU old-style field designator extension}} |
| 13 |
|
| 14 |
Point p2 = { |
| 15 |
.x = 17, // expected-warning {{mixture of designated and non-designated initializers in the same initializer list is a C99 extension}} |
| 16 |
25 // expected-note {{first non-designated initializer}} |
| 17 |
}; |
| 18 |
|
| 19 |
Point p3 = { |
| 20 |
.x = 17, // expected-note {{previous initialization is here}} |
| 21 |
.x = 18, // expected-warning {{initializer overrides prior initialization of this subobject}} |
| 22 |
}; |
| 23 |
|
| 24 |
Point p4 = { |
| 25 |
.x = 17, // expected-warning {{mixture of designated and non-designated initializers in the same initializer list is a C99 extension}} |
| 26 |
25, // expected-note {{first non-designated initializer}} |
| 27 |
// expected-note@-1 {{previous initialization is here}} |
| 28 |
.y = 18, // expected-warning {{initializer overrides prior initialization of this subobject}} |
| 29 |
}; |
| 30 |
|
| 31 |
int arr[1] = {[0] = 0}; // expected-warning {{array designators are a C99 extension}} |
| 32 |
|
| 33 |
struct Pt { int x, y; }; |
| 34 |
struct Rect { Pt tl, br; }; |
| 35 |
Rect r = { |
| 36 |
.tl.x = 0 // expected-warning {{nested designators are a C99 extension}} |
| 37 |
}; |
| 38 |
|
| 39 |
struct NonTrivial { |
| 40 |
NonTrivial(); |
| 41 |
~NonTrivial(); |
| 42 |
}; |
| 43 |
struct S { |
| 44 |
int a; |
| 45 |
NonTrivial b; |
| 46 |
}; |
| 47 |
struct T { |
| 48 |
S s; |
| 49 |
}; |
| 50 |
S f(); |
| 51 |
|
| 52 |
T t1 = { |
| 53 |
.s = f() |
| 54 |
}; |
| 55 |
|
| 56 |
// It's important that we reject this; we would not destroy the existing |
| 57 |
// 'NonTrivial' object before overwriting it (and even calling its destructor |
| 58 |
// would not necessarily be correct). |
| 59 |
T t2 = { |
| 60 |
.s = f(), // expected-note {{previous}} |
| 61 |
.s.b = NonTrivial() // expected-error {{initializer would partially override prior initialization of object of type 'S' with non-trivial destruction}} |
| 62 |
// expected-warning@-1 {{nested}} |
| 63 |
}; |
| 64 |
|
| 65 |
// FIXME: It might be reasonable to accept this. |
| 66 |
T t3 = { |
| 67 |
.s = f(), // expected-note {{previous}} |
| 68 |
.s.a = 0 // expected-error {{initializer would partially override prior initialization of object of type 'S' with non-trivial destruction}} |
| 69 |
// expected-warning@-1 {{nested}} |
| 70 |
}; |