71 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -pedantic -verify=expected,cxx17 -std=c++17 %s2// RUN: %clang_cc1 -fsyntax-only -pedantic -verify=expected,cxx20 -std=c++2a %s3 4// cxx17-warning@* 0+{{designated initializers are a C++20 extension}}5 6void f1(int i[static 5]) { // expected-error{{C99}}7}8 9struct Point { int x; int y; int z[]; }; // expected-warning{{flexible array members are a C99 feature}}10 11Point p1 = { .x = 17,12 y: 25 }; // expected-warning{{use of GNU old-style field designator extension}}13 14Point 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 19Point p3 = {20 .x = 17, // expected-note {{previous initialization is here}}21 .x = 18, // expected-warning {{initializer overrides prior initialization of this subobject}}22};23 24Point 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 31int arr[1] = {[0] = 0}; // expected-warning {{array designators are a C99 extension}}32 33struct Pt { int x, y; };34struct Rect { Pt tl, br; };35Rect r = {36 .tl.x = 0 // expected-warning {{nested designators are a C99 extension}}37};38 39struct NonTrivial {40 NonTrivial();41 ~NonTrivial();42};43struct S {44 int a;45 NonTrivial b;46};47struct T {48 S s;49};50S f();51 52T t1 = {53 .s = f()54};55 56// It's important that we reject this; we would not destroy the existing57// 'NonTrivial' object before overwriting it (and even calling its destructor58// would not necessarily be correct).59T 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.66T 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};71