Fix the clang-wpa example.
[clang.git] / test / Sema / flexible-array-init.c
blob12f5d4f5d6059d93fa4cc57691c7c1088abede69
1 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
2 struct 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}}
7 struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}}
9 void test() {
10 struct one x3 = {5, {1, 2, 3}}; // \
11 // expected-warning{{flexible array initialization is a GNU extension}} \
12 // expected-error {{non-static initialization of a variable with flexible array member}}
13 struct one x3a = { 5 };
14 struct one x3b = { .a = 5 };
15 struct one x3c = { 5, {} }; // expected-warning{{use of GNU empty initializer extension}} \
16 // expected-warning{{flexible array initialization is a GNU extension}} \
17 // expected-warning{{zero size arrays are an extension}}
20 struct foo {
21 int x;
22 int y[]; // expected-note 6 {{initialized flexible array member 'y' is here}}
23 };
24 struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
26 struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}}
27 struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
28 struct bar c = { { 1, { } } }; // // expected-warning{{flexible array initialization is a GNU extension}} \
29 // expected-warning{{use of GNU empty initializer extension}} \
30 // expected-warning{{zero size arrays are an extension}}
31 struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-warning{{'struct foo' may not be used as an array element due to flexible array member}} \
32 // expected-error{{non-empty initialization of flexible array member inside subobject}}
34 struct foo desig_foo = { .y = {2, 3, 4} };
35 struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \
36 // expected-warning{{zero size arrays are an extension}}
37 struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
38 struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}}
40 struct point {
41 int x, y;
44 struct polygon {
45 int numpoints;
46 struct point points[]; // expected-note{{initialized flexible array member 'points' is here}}
48 struct polygon poly = {
49 .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}}
51 // PR3540
52 struct X {
53 int a;
54 int b;
55 char data[];
58 struct Y {
59 int a:4;
60 int b:4;
61 int c;
62 int d;
63 int e;
64 struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}}
68 // PR8217
69 struct PR8217a {
70 int i;
71 char v[];
74 void PR8217() {
75 struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{non-static initialization of a variable with flexible array member}}
76 struct PR8217a foo2 = { .i = 0 };
77 struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{non-static initialization of a variable with flexible array member}}
78 struct PR8217a bar;