[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / c99.cpp
blob9fbc45bc2031bf74eefc754dc1fbb4a30d87b239
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
4 // cxx17-warning@* 0+{{designated initializers are a C++20 extension}}
6 void f1(int i[static 5]) { // expected-error{{C99}}
9 struct Point { int x; int y; int z[]; }; // expected-warning{{flexible array members are a C99 feature}}
11 Point p1 = { .x = 17,
12 y: 25 }; // expected-warning{{use of GNU old-style field designator extension}}
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}}
19 Point p3 = {
20 .x = 17, // expected-note {{previous initialization is here}}
21 .x = 18, // expected-warning {{initializer overrides prior initialization of this subobject}}
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}}
31 int arr[1] = {[0] = 0}; // expected-warning {{array designators are a C99 extension}}
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}}
39 struct NonTrivial {
40 NonTrivial();
41 ~NonTrivial();
43 struct S {
44 int a;
45 NonTrivial b;
47 struct T {
48 S s;
50 S f();
52 T t1 = {
53 .s = f()
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}}
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}}