[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / flexible-array-init.c
blobd3620154c5f0ce65dde507b0447659c8ad88f1ce
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(void) {
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}}
18 struct foo {
19 int x;
20 int y[]; // expected-note 8 {{initialized flexible array member 'y' is here}}
21 };
22 struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
24 struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}}
25 struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{initialization of flexible array member is not allowed}}
26 struct 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}}
29 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}} \
30 // expected-error{{initialization of flexible array member is not allowed}}
32 struct foo desig_foo = { .y = {2, 3, 4} }; // expected-warning{{flexible array initialization is a GNU extension}}
33 struct 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}}
36 struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{initialization of flexible array member is not allowed}}
37 struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}}
39 struct point {
40 int x, y;
43 struct polygon {
44 int numpoints;
45 struct point points[]; // expected-note{{initialized flexible array member 'points' is here}}
47 struct polygon poly = {
48 .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}}
50 // PR3540
51 struct X {
52 int a;
53 int b;
54 char data[];
57 struct 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}}
67 // PR8217
68 struct PR8217a {
69 int i;
70 char v[]; // expected-note 2 {{initialized flexible array member 'v' is here}}
73 void PR8217(void) {
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;
80 typedef struct PR10648 {
81 unsigned long n;
82 int v[]; // expected-note {{initialized flexible array member 'v' is here}}
83 } PR10648;
84 int f10648(void) {
85 return (PR10648){2, {3, 4}}.v[1]; // expected-error {{initialization of flexible array member is not allowed}}
88 struct FlexWithUnnamedBitfield { int : 10; int x; int y[]; }; // expected-note {{initialized flexible array member 'y' is here}}
89 void TestFlexWithUnnamedBitfield(void) {
90 struct FlexWithUnnamedBitfield x = {10, {3}}; // expected-error {{initialization of flexible array member is not allowed}}