summaryrefslogtreecommitdiff
path: root/test/SemaCXX/c99.cpp
blob: 9fbc45bc2031bf74eefc754dc1fbb4a30d87b239 (plain)
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
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify=expected,cxx17 -std=c++17 %s
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify=expected,cxx20 -std=c++2a %s

// cxx17-warning@* 0+{{designated initializers are a C++20 extension}}

void f1(int i[static 5]) { // expected-error{{C99}}
}

struct Point { int x; int y; int z[]; }; // expected-warning{{flexible array members are a C99 feature}}

Point p1 = { .x = 17,
             y: 25 }; // expected-warning{{use of GNU old-style field designator extension}}

Point p2 = {
  .x = 17, // expected-warning {{mixture of designated and non-designated initializers in the same initializer list is a C99 extension}}
  25 // expected-note {{first non-designated initializer}}
};

Point p3 = {
  .x = 17, // expected-note {{previous initialization is here}}
  .x = 18, // expected-warning {{initializer overrides prior initialization of this subobject}}
};

Point p4 = {
  .x = 17, // expected-warning {{mixture of designated and non-designated initializers in the same initializer list is a C99 extension}}
  25, // expected-note {{first non-designated initializer}}
  // expected-note@-1 {{previous initialization is here}}
  .y = 18, // expected-warning {{initializer overrides prior initialization of this subobject}}
};

int arr[1] = {[0] = 0}; // expected-warning {{array designators are a C99 extension}}

struct Pt { int x, y; };
struct Rect { Pt tl, br; };
Rect r = {
  .tl.x = 0 // expected-warning {{nested designators are a C99 extension}}
};

struct NonTrivial {
  NonTrivial();
  ~NonTrivial();
};
struct S {
  int a;
  NonTrivial b;
};
struct T {
  S s;
};
S f();

T t1 = {
  .s = f()
};

// It's important that we reject this; we would not destroy the existing
// 'NonTrivial' object before overwriting it (and even calling its destructor
// would not necessarily be correct).
T t2 = {
  .s = f(), // expected-note {{previous}}
  .s.b = NonTrivial() // expected-error {{initializer would partially override prior initialization of object of type 'S' with non-trivial destruction}}
  // expected-warning@-1 {{nested}}
};

// FIXME: It might be reasonable to accept this.
T t3 = {
  .s = f(), // expected-note {{previous}}
  .s.a = 0 // expected-error {{initializer would partially override prior initialization of object of type 'S' with non-trivial destruction}}
  // expected-warning@-1 {{nested}}
};