1 // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wno-gnu
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wgnu
3 // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wno-gnu \
4 // RUN: -Wgnu-alignof-expression -Wgnu-case-range -Wgnu-complex-integer -Wgnu-conditional-omitted-operand \
5 // RUN: -Wgnu-empty-initializer -Wgnu-label-as-value -Wgnu-statement-expression \
6 // RUN: -Wgnu-compound-literal-initializer -Wgnu-flexible-array-initializer \
7 // RUN: -Wgnu-redeclared-enum -Wgnu-folding-constant -Wgnu-empty-struct \
8 // RUN: -Wgnu-union-cast -Wgnu-variable-sized-type-not-at-end
9 // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \
10 // RUN: -Wno-gnu-alignof-expression -Wno-gnu-case-range -Wno-gnu-complex-integer -Wno-gnu-conditional-omitted-operand \
11 // RUN: -Wno-gnu-empty-initializer -Wno-gnu-label-as-value -Wno-gnu-statement-expression \
12 // RUN: -Wno-gnu-compound-literal-initializer -Wno-gnu-flexible-array-initializer \
13 // RUN: -Wno-gnu-redeclared-enum -Wno-gnu-folding-constant -Wno-gnu-empty-struct \
14 // RUN: -Wno-gnu-union-cast -Wno-gnu-variable-sized-type-not-at-end
15 // Additional disabled tests:
16 // %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -Wno-gnu -Wgnu-alignof-expression
17 // %clang_cc1 -fsyntax-only -verify %s -DCASERANGE -Wno-gnu -Wgnu-case-range
18 // %clang_cc1 -fsyntax-only -verify %s -DCOMPLEXINT -Wno-gnu -Wgnu-complex-integer
19 // %clang_cc1 -fsyntax-only -verify %s -DOMITTEDOPERAND -Wno-gnu -Wgnu-conditional-omitted-operand
20 // %clang_cc1 -fsyntax-only -verify %s -DEMPTYINIT -Wno-gnu -Wgnu-empty-initializer
21 // %clang_cc1 -fsyntax-only -verify %s -DLABELVALUE -Wno-gnu -Wgnu-label-as-value
22 // %clang_cc1 -fsyntax-only -verify %s -DSTATEMENTEXP -Wno-gnu -Wgnu-statement-expression
23 // %clang_cc1 -fsyntax-only -verify %s -DSTATEMENTEXPMACRO -Wno-gnu -Wgnu-statement-expression-from-macro-expansion
24 // %clang_cc1 -fsyntax-only -verify %s -DCOMPOUNDLITERALINITIALIZER -Wno-gnu -Wgnu-compound-literal-initializer
25 // %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYINITIALIZER -Wno-gnu -Wgnu-flexible-array-initializer
26 // %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDENUM -Wno-gnu -Wgnu-redeclared-enum
27 // %clang_cc1 -fsyntax-only -verify %s -DUNIONCAST -Wno-gnu -Wgnu-union-cast
28 // %clang_cc1 -fsyntax-only -verify %s -DVARIABLESIZEDTYPENOTATEND -Wno-gnu -Wgnu-variable-sized-type-not-at-end
29 // %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant
30 // %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct
31
32 #if NONE
33 // expected-no-diagnostics
34 #endif
35
36
37 #if ALL || ALIGNOF
38 // expected-warning@+4 {{'_Alignof' applied to an expression is a GNU extension}}
39 #endif
40
41 char align;
42 _Static_assert(_Alignof(align) > 0, "align's alignment is wrong");
43
44
45 #if ALL || CASERANGE
46 // expected-warning@+5 {{use of GNU case range extension}}
47 #endif
48
caserange(int x)49 void caserange(int x) {
50 switch (x) {
51 case 42 ... 44: ;
52 }
53 }
54
55
56 #if ALL || COMPLEXINT
57 // expected-warning@+3 {{complex integer types are a GNU extension}}
58 #endif
59
60 _Complex short int complexint;
61
62
63 #if ALL || OMITTEDOPERAND
64 // expected-warning@+3 {{use of GNU ?: conditional expression extension, omitting middle operand}}
65 #endif
66
67 static const char* omittedoperand = (const char*)0 ?: "Null";
68
69
70 #if ALL || EMPTYINIT
71 // expected-warning@+3 {{use of GNU empty initializer extension}}
72 #endif
73
74 struct { int x; } emptyinit = {};
75
76
77 #if ALL || LABELVALUE
78 // expected-warning@+6 {{use of GNU address-of-label extension}}
79 // expected-warning@+7 {{use of GNU indirect-goto extension}}
80 #endif
81
labelvalue(void)82 void labelvalue(void) {
83 void *ptr;
84 ptr = &&foo;
85 foo:
86 goto *ptr;
87 }
88
89
90 #if ALL || STATEMENTEXP
91 // expected-warning@+5 {{use of GNU statement expression extension}}
92 #endif
93
statementexp(void)94 void statementexp(void)
95 {
96 int a = ({ 1; });
97 }
98
99 #if ALL || STATEMENTEXP || STATEMENTEXPMACRO
100 // expected-warning@+5 {{use of GNU statement expression extension from macro expansion}}
101 #endif
102
103 #define STMT_EXPR_MACRO(a) ({ (a); })
statementexprmacro(void)104 void statementexprmacro(void) {
105 int a = STMT_EXPR_MACRO(1);
106 }
107
108 #if ALL || COMPOUNDLITERALINITIALIZER
109 // expected-warning@+4 {{initialization of an array of type 'int[5]' from a compound literal of type 'int[5]' is a GNU extension}}
110 #endif
111
112 typedef int int5[5];
113 int cli[5] = (int[]){1, 2, 3, 4, 5};
114
115
116 #if ALL || FLEXIBLEARRAYINITIALIZER
117 // expected-note@+6 {{initialized flexible array member 'y' is here}}
118 // expected-warning@+6 {{flexible array initialization is a GNU extension}}
119 #endif
120
121 struct fai {
122 int x;
123 int y[];
124 } fai = { 1, { 2, 3, 4 } };
125
126
127 #if ALL || FOLDINGCONSTANT
128 // expected-warning@+5 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
129 // expected-warning@+7 {{variable length array folded to constant array as an extension}}
130 #endif
131
132 enum {
133 fic = (int)(0.75 * 1000 * 1000)
134 };
135 static const int size = 100;
136 int data[size];
137
foo(void)138 void foo(void) { int data[size]; } // OK, always a VLA
139
140 #if ALL || REDECLAREDENUM
141 // expected-note@+4 {{previous definition is here}}
142 // expected-warning@+8 {{redeclaration of already-defined enum 'RE' is a GNU extension}}
143 #endif
144
145 enum RE {
146 Val1,
147 Val2
148 };
149
150 enum RE;
151
152
153 #if ALL || UNIONCAST
154 // expected-warning@+4 {{cast to union type is a GNU extension}}
155 #endif
156
157 union uc { int i; unsigned : 3; };
158 union uc w = (union uc)2;
159
160
161 #if ALL || VARIABLESIZEDTYPENOTATEND
162 // expected-warning@+8 {{field 'hdr' with variable sized type 'struct vst' not at the end of a struct or class is a GNU extension}}
163 #endif
164
165 struct vst {
166 short tag_type;
167 char tag_data[];
168 };
169 struct vstnae {
170 struct vst hdr;
171 char data;
172 };
173
174
175 #if ALL || EMPTYSTRUCT
176 // expected-warning@+4 {{empty struct is a GNU extension}}
177 // expected-warning@+4 {{struct without named members is a GNU extension}}
178 #endif
179
180 const struct {} es;
181 struct {int:5;} swnm;
182
183