1// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
2struct one {
3  int a;
4  int values[]; // expected-note 4{{initialized flexible array member 'values' is here}}
5} x = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}}
6
7struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}}
8
9void test() {
10  struct one x3 = {5, {1, 2, 3}}; // expected-error{{initialization of flexible array member is not allowed}}
11  struct one x3a = { 5 };
12  struct one x3b = { .a = 5 };
13  struct one x3c = { 5, {} }; // expected-warning{{use of GNU empty initializer extension}} \
14  // expected-warning{{flexible array initialization is a GNU extension}} \
15  // expected-warning{{zero size arrays are an extension}}
16}
17
18struct foo {
19  int x;
20  int y[]; // expected-note 8 {{initialized flexible array member 'y' is here}}
21};
22struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
23
24struct foo a = { 1, { 2, 3, 4 } };        // expected-warning{{flexible array initialization is a GNU extension}}
25struct bar b = { { 1, { 2, 3, 4 } } };    // expected-error{{initialization of flexible array member is not allowed}}
26struct bar c = { { 1, { } } };            // // expected-warning{{flexible array initialization is a GNU extension}} \
27              // expected-warning{{use of GNU empty initializer extension}} \
28              // expected-warning{{zero size arrays are an extension}}
29struct foo d[1] = { { 1, { 2, 3, 4 } } };  // expected-warning{{'struct foo' may not be used as an array element due to flexible array member}} \
30              // expected-error{{initialization of flexible array member is not allowed}}
31
32struct foo desig_foo = { .y = {2, 3, 4} }; // expected-warning{{flexible array initialization is a GNU extension}}
33struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \
34  // expected-warning{{zero size arrays are an extension}} \
35  // expected-warning{{flexible array initialization is a GNU extension}}
36struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{initialization of flexible array member is not allowed}}
37struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}}
38
39struct point {
40  int x, y;
41};
42
43struct polygon {
44  int numpoints;
45  struct point points[]; // expected-note{{initialized flexible array member 'points' is here}}
46};
47struct polygon poly = {
48  .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}}
49
50// PR3540
51struct X {
52  int a;
53  int b;
54  char data[];
55};
56
57struct Y {
58  int a:4;
59  int b:4;
60  int c;
61  int d;
62  int e;
63  struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}}
64};
65
66
67// PR8217
68struct PR8217a {
69  int  i;
70  char v[]; // expected-note 2 {{initialized flexible array member 'v' is here}}
71};
72
73void PR8217() {
74  struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{initialization of flexible array member is not allowed}}
75  struct PR8217a foo2 = { .i = 0 };
76  struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{initialization of flexible array member is not allowed}}
77  struct PR8217a bar;
78}
79
80typedef struct PR10648 {
81 unsigned long n;
82 int v[]; // expected-note {{initialized flexible array member 'v' is here}}
83} PR10648;
84int f10648() {
85  return (PR10648){2, {3, 4}}.v[1]; // expected-error {{initialization of flexible array member is not allowed}}
86}
87
88struct FlexWithUnnamedBitfield { int : 10; int x; int y[]; }; // expected-note {{initialized flexible array member 'y' is here}}
89void TestFlexWithUnnamedBitfield() {
90  struct FlexWithUnnamedBitfield x = {10, {3}}; // expected-error {{initialization of flexible array member is not allowed}}
91}
92