1 /* RUN: %clang_cc1 -std=c89 -fsyntax-only -Wvla -verify=expected,c89only,c17andearlier -pedantic -Wno-c11-extensions %s
2 RUN: %clang_cc1 -std=c99 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic -Wno-c11-extensions %s
3 RUN: %clang_cc1 -std=c11 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s
4 RUN: %clang_cc1 -std=c17 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s
5 RUN: %clang_cc1 -std=c2x -fsyntax-only -Wvla -verify=expected,c99andup,c23andup -pedantic %s
8 /* The following are DRs which do not require tests to demonstrate
9 * conformance or nonconformance.
12 * Translation-time expresssion evaluation
15 * Meaning of FE_* macros in <fenv.h>
18 * Breaking up the very long sentence describing preprocessing directive
21 * Clarifiying arguments vs. parameters
24 * Clarify that source files et al. need not be "files"
27 * Add non-corner case example of trigraphs
30 * Meaning of "known constant size"
33 * Missing Predefined Macro Name
36 * VLAs and conditional expressions
41 * Adding underscore to portable include file name character set
43 #include "./abc_123.h"
44 #ifndef WE_SUPPORT_DR302
45 #error "Oh no, we don't support DR302 after all!"
49 * Clarifying illegal tokens in #if directives
51 /* expected-error@+3 {{invalid token at start of a preprocessor expression}}
52 expected-warning@+3 {{missing terminating ' character}}
58 * Clarifying handling of keywords in #if directives
61 #error "We definitely should not have gotten here"
65 * Clarifying that rescanning applies to object-like macros
70 #error "We definitely should not have gotten here"
74 * Definition of variably modified types
77 typedef int vla[x]; /* expected-warning {{variable length array}} */
79 /* Ensure that a constant array of variable-length arrays are still
80 * considered a variable-length array.
82 vla y[3]; /* expected-warning {{variable length array}} */
86 * Incomplete arrays of VLAs
89 int c[][i] = { 0 }; /* expected-error {{variable-sized object may not be initialized}}
90 expected-warning {{variable length array}}
95 * Implementation-defined bit-field types
98 unsigned long long a : 37; /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
99 unsigned long long b : 37; /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
104 _Static_assert(sizeof(dr315.a + dr315.b) == sizeof(unsigned long long), ""); /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
105 /* Demonstrate that integer promotions still happen when less than the width of
108 _Static_assert(sizeof(dr315.c + dr315.d) == sizeof(int), "");
110 #if __STDC_VERSION__ < 202311L
112 * Unprototyped function types
114 void dr316_1(a) int a; {} /* expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}} */
115 void (*dr316_1_ptr)(int, int, int) = dr316_1;
118 * Function definitions with empty parentheses
120 * Despite the function with empty parens being a definition, this does not
121 * provide a prototype for the function. However, calling the function with
122 * arguments is undefined behavior, so it is defensible for us to warn the user
123 * about it. They key point to this DR is that we give the "without a
124 * prototype" warnings to demonstrate we don't give this function a prototype.
126 void dr317_1() {} /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */
129 dr317_1(1); /* expected-warning {{too many arguments in call to 'dr317_1'}}
130 expected-warning {{passing arguments to 'dr317_1' without a prototype is deprecated in all versions of C and is not supported in C23}}
133 #endif /* __STDC_VERSION__ < 202311L */
136 * Scope of variably modified type
139 typedef int dr320_t
[dr320_v
]; /* c89only-warning {{variable length arrays are a C99 feature}}
140 expected-error {{variable length array declaration not allowed at file scope}}
141 c99andup-warning {{variable length array used}}
143 void dr320(int okay
[dr320_v
]) { /* c89only-warning {{variable length arrays are a C99 feature}}
144 c99andup-warning {{variable length array used}}
146 typedef int type
[dr320_v
]; /* c89only-warning {{variable length arrays are a C99 feature}}
147 c99andup-warning {{variable length array used}}
149 extern type bad
; /* expected-error {{variable length array declaration cannot have 'extern' linkage}} */
151 /* C99 6.7.5.2p2, second sentence. */
152 static type fine
; /* expected-error {{variable length array declaration cannot have 'static' storage duration}} */
156 * Wide character code values for members of the basic character set
159 ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' && \
161 'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' && \
162 'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' && \
163 'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' && \
164 'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' && \
165 'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' && \
167 'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' && \
168 'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' && \
169 'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' && \
170 'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' && \
171 'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' && \
173 '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' && \
174 '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' && \
176 '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' && \
177 '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' && \
178 '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' && \
179 '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' && \
180 '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' && \
181 ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\'' \
183 #if __STDC_MB_MIGHT_NEQ_WC__
184 #ifndef __FreeBSD__ /* PR22208, FreeBSD expects us to give a bad (but conforming) answer here. */
185 _Static_assert(!DR321
, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation");
188 _Static_assert(DR321
, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs");
191 /* WG14 DR328: partial
192 * String literals in compound literal initialization
194 * DR328 is implemented properly in terms of allowing string literals, but is
195 * not implemented. See DR339 (marked as a duplicate of this one) for details.
197 const char *dr328_v
= (const char *){"this is a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */
199 const char *val
= (const char *){"also a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */
205 * See dr335.c also, which tests the runtime behavior of the part of the DR
206 * which will compile.
210 _Bool bbf3
: 3; /* expected-error {{width of bit-field 'bbf3' (3 bits) exceeds the width of its type (1 bit)}}
211 c89only-warning {{'_Bool' is a C99 extension}}
216 /* WG14 DR339: dup 328
217 * Variably modified compound literals
219 * This DR is marked as a duplicate of DR328, see that DR for further
222 * FIXME: we should be diagnosing this compound literal as creating a variably-
223 * modified type at file scope, as we would do for a file scope variable.
226 void *dr339
= &(int (*)[dr339_v
]){ 0 }; /* c89only-warning {{variable length arrays are a C99 feature}}
227 c99andup-warning {{variable length array used}}
228 c89only-warning {{compound literals are a C99-specific feature}}
232 * Composite types for variable-length arrays
234 * The DR made this behavior undefined because implementations disagreed on the
235 * behavior. For this DR, Clang accepts the code and GCC rejects it. It's
236 * unclear whether the Clang behavior is intentional, but because the code is
237 * UB, any behavior is acceptable.
239 #if __STDC_VERSION__ < 202311L
240 void dr340(int x
, int y
) {
241 typedef void (*T1
)(int);
242 typedef void (*T2
)(); /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */
245 T2 (*b
)[x
] = 0; /* c89only-warning {{variable length arrays are a C99 feature}}
246 c99andup-warning {{variable length array used}}
250 #endif /* __STDC_VERSION__ < 202311L */
253 * [*] in abstract declarators
255 void dr341_1(int (*)[*]); /* c89only-warning {{variable length arrays are a C99 feature}}
256 c99andup-warning {{variable length array used}}
258 void dr341_2(int (*)[sizeof(int (*)[*])]); /* expected-error {{star modifier used outside of function prototype}} */
261 * Initializing qualified wchar_t arrays
264 const __WCHAR_TYPE__ x
[] = L
"foo";
268 * Casts in preprocessor conditional expressions
270 * Note: this DR removed a constraint about not containing casts because there
271 * are no keywords, therefore no types to cast to, so casts simply don't exist
272 * as a construct during preprocessing.
275 #error "this should not be an error, we shouldn't get here"
277 /* expected-error@+1 {{"reached"}} */
282 * Where does parameter scope start?
284 void f(long double f
,
285 char (**a
)[10 * sizeof f
]) {
286 _Static_assert(sizeof **a
== sizeof(long double) * 10, "");
290 * Clarifying trigraph substitution
292 int dr309
??(1??) = { 1 }; /* c17andearlier-warning {{trigraph converted to '[' character}}
293 c17andearlier-warning {{trigraph converted to ']' character}}
294 c23andup-warning 2 {{trigraph ignored}}
295 c23andup-error {{expected ';' after top level declarator}}
298 /* NOTE: Due to interactions with the diagnostic system, dr309 should be the
299 * last test case in this file because subsequent diagnostics may not be
300 * generated as expected.