| 1 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override,reorder -Werror=c99-designator %s |
| 2 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override -Wno-reorder-init-list -Werror=initializer-overrides %s |
| 3 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=reorder -Wno-initializer-overrides -Werror=reorder-init-list %s |
| 4 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=good -Wno-c99-designator %s |
| 5 |
// good-no-diagnostics |
| 6 |
|
| 7 |
// Ensure that -Wc99-designator controls both -Winitializer-overrides and |
| 8 |
// -Wreorder-init-list. |
| 9 |
|
| 10 |
struct X { |
| 11 |
int a; |
| 12 |
int b; |
| 13 |
}; |
| 14 |
|
| 15 |
void test() { |
| 16 |
X x{.a = 0, // override-note {{previous initialization is here}} |
| 17 |
.a = 1}; // override-error {{initializer overrides prior initialization of this subobject}} |
| 18 |
X y{.b = 0, // reorder-note {{previous initialization for field 'b' is here}} |
| 19 |
.a = 1}; // reorder-error {{ISO C++ requires field designators to be specified in declaration order; field 'b' will be initialized after field 'a'}} |
| 20 |
} |
| 21 |
|