1 /* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-c11-extensions %s
2 RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
3 RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
4 RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
5 RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic %s
8 /* The following are DRs which do not require tests to demonstrate
9 * conformance or nonconformance.
12 * Defect with the return statement
15 * Incomplete tag types in a parameter list
18 * Are undefined values and undefined behavior the same?
21 * Formal parameters having array-of-non-object types
24 * Abstract semantics, sequence points, and expression evaluation
27 * Conversions of pointer values to integral types
30 * Conversion/widening of bit-fields
33 * Using things declared as 'extern (qualified) void'
36 * Composite type of an enumerated type and an integral type
39 * Can undefined behavior occur at translation time, or only at run time?
42 * Undefined behavior not previously listed in subclause G2
45 * Is there an allocated storage duration?
48 * Compatibility of complete and incomplete types
54 * Sequence points in library functions
57 * Defining library functions
63 * Consistency of implementation-defined values
66 * Consistency of the C Standard Defects exist in the way the Standard refers
70 * Details of reserved symbols
78 * Type qualifiers and "as if by assignment"
80 void dr101_callee(const int val
);
81 void dr101_caller(void) {
83 dr101_callee(val
); /* ok; const qualifier on the parameter doesn't prevent as-if assignment. */
87 * Tag redeclaration constraints
90 struct S
{ int member
; }; /* expected-note {{previous definition is here}} */
91 struct S
{ int member
; }; /* expected-error {{redefinition of 'S'}} */
93 union U
{ int member
; }; /* expected-note {{previous definition is here}} */
94 union U
{ int member
; }; /* expected-error {{redefinition of 'U'}} */
96 enum E
{ member
}; /* expected-note 2{{previous definition is here}} */
97 enum E
{ member
}; /* expected-error {{redefinition of 'E'}}
98 expected-error {{redefinition of enumerator 'member'}} */
102 * Formal parameters of incomplete type
104 void dr103_1(int arg
[]); /* ok, not an incomplete type due to rewrite */
105 void dr103_2(struct S s
) {} /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
106 expected-error {{variable has incomplete type 'struct S'}}
107 expected-note {{forward declaration of 'struct S'}} */
108 void dr103_3(struct S s
); /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
109 expected-note {{previous declaration is here}} */
110 void dr103_3(struct S
{ int a
; } s
) { } /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
111 expected-error {{conflicting types for 'dr103_3'}} */
112 void dr103_4(struct S s1
, struct S
{ int a
; } s2
); /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}} */
114 /* WG14 DR105: dup 017
115 * Precedence of requirements on compatible types
117 * NB: This is also Question 3 from DR017.
120 /* According to C2x 6.7.6.3p14 the return type and parameter types to be
121 * compatible types, but qualifiers are dropped from the parameter type.
123 extern void func(int);
124 extern void func(const int); /* FIXME: this should be pedantically diagnosed. */
126 extern void other_func(int); /* expected-note {{previous declaration is here}} */
127 extern void other_func(int *); /* expected-error {{conflicting types for 'other_func'}} */
129 extern int i
; /* expected-note {{previous declaration is here}} */
130 extern float i
; /* expected-error {{redeclaration of 'i' with a different type: 'float' vs 'int'}} */
134 * When can you dereference a void pointer?
136 * NB: This is a partial duplicate of DR012.
138 void dr106(void *p
, int i
) {
139 /* The behavior changed between C89 and C99. */
140 (void)&*p
; /* c89only-warning {{ISO C forbids taking the address of an expression of type 'void'}}
141 c89only-warning {{ISO C does not allow indirection on operand of type 'void *'}} */
143 /* The behavior of all three of these is undefined. */
144 (void)*p
; /* expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}*/
146 (void)&(*p
); /* c89only-warning {{ISO C forbids taking the address of an expression of type 'void'}}
147 expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}*/
149 (void)(i
? *p
: *p
); /* expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}
150 expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}*/
152 (void)(*p
, *p
); /* expected-warning {{left operand of comma operator has no effect}}
153 expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}
154 expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}*/
158 * Can a macro identifier hide a keyword?
164 const int j
= 12; /* expected-note {{variable 'j' declared const here}} */
166 i
= 100; /* Okay, the keyword was hidden by the macro. */
167 j
= 100; /* expected-error {{cannot assign to variable 'j' with const-qualified type 'const int'}} */
171 * Conversion of pointer-to-qualified type values to type (void*) values
173 void dr111(const char *ccp
, void *vp
) {
174 vp
= ccp
; /* expected-warning {{assigning to 'void *' from 'const char *' discards qualifiers}} */
178 * Null pointer constants and relational comparisons
180 void dr112(void *vp
) {
181 /* The behavior of this expression is pedantically undefined.
182 * FIXME: should we diagnose under -pedantic?
184 (void)(vp
> (void*)0);
188 * Return expressions in functions declared to return qualified void
190 volatile void dr113_v(volatile void *vvp
) { /* expected-warning {{function cannot return qualified void type 'volatile void'}} */
191 return *vvp
; /* expected-warning {{void function 'dr113_v' should not return void expression}}
192 expected-warning{{ISO C does not allow indirection on operand of type 'volatile void *'}} */
194 const void dr113_c(const void *cvp
) { /* expected-warning {{function cannot return qualified void type 'const void'}} */
195 return *cvp
; /* expected-warning {{void function 'dr113_c' should not return void expression}}
196 expected-warning{{ISO C does not allow indirection on operand of type 'const void *'}} */
200 * Initialization of multi-dimensional char array objects
203 char array
[2][5] = { "defghi" }; /* expected-warning {{initializer-string for char array is too long}} */
207 * Member declarators as declarators
210 struct { int mbr
; }; /* expected-warning {{declaration does not declare anything}} */
211 union { int mbr
; }; /* expected-warning {{declaration does not declare anything}} */
215 * Implicit unary & applied to register arrays
218 register int array
[5] = { 0, 1, 2, 3, 4 };
219 (void)array
; /* expected-error {{address of register variable requested}} */
220 (void)array
[3]; /* expected-error {{address of register variable requested}} */
221 (void)(array
+ 3); /* expected-error {{address of register variable requested}} */
225 * Completion point for enumerated types
229 /* The enum isn't a complete type until the closing }, but an
230 * implementation may complete the type earlier if it has sufficient type
231 * information to calculate size or alignment, etc.
233 * On Microsoft targets, an enum is always implicit int sized, so the type
234 * is sufficiently complete there. On other platforms, it is an incomplete
235 * type at this point.
239 /* expected-error@-2 {{invalid application of 'sizeof' to an incomplete type 'enum E'}} */
240 /* expected-note@-12 {{definition of 'enum E' is not complete until the closing '}'}} */
246 * Initialization of multi-dimensional array objects
249 static int array
[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; /* expected-error {{array has incomplete element type 'int[]'}} */
253 * Semantics of assignment to (and initialization of) bit-fields
256 /* We could verify this one with a codegen test to ensure that the proper
257 * value is stored into bit, but the diagnostic tells us what the value is
258 * after conversion, so we can lean on that for verification.
260 struct S
{ unsigned bit
:1; };
261 struct S object1
= { 3 }; /* expected-warning {{implicit truncation from 'int' to bit-field changes value from 3 to 1}} */
263 object2
.bit
= 3; /* expected-warning {{implicit truncation from 'int' to bit-field changes value from 3 to 1}} */
267 * 'Type categories' and qualified types
270 /* Both of these examples are strictly conforming. */
272 enumerator1
= (const int) 9
275 enumerator2
= (volatile int) 9
280 * Casts to 'a void type' versus casts to 'the void type'
283 /* A cast can cast to void or any qualified version of void. */
284 (const volatile void)0;
288 * What does 'synonym' mean with respect to typedef names?
292 const IP object
; /* expected-note {{variable 'object' declared const here}} */
294 /* The root of the DR is whether 'object' is a pointer to a const int, or a
295 * const pointer to int.
297 *object
= 12; /* ok */
298 ++object
; /* expected-error {{cannot assign to variable 'object' with const-qualified type 'const IP' (aka 'int *const')}} */
302 * Editorial issue relating to tag declarations in type specifiers
306 struct TAG
{ int i
; };
309 struct TAG object
; /* expected-error {{variable has incomplete type 'struct TAG'}}
310 expected-note {{forward declaration of 'struct TAG'}}
316 * Tags and name spaces
318 struct dr129_t
{ int i
; };
320 enum dr129_t
{ enumerator
}; /* expected-note {{previous use is here}} */
323 (void)(struct dr129_t
*)vp
; /* expected-error {{use of 'dr129_t' with tag type that does not match previous declaration}} */
327 * const member qualification and assignment
331 const int i
; /* expected-note {{data member 'i' declared const here}} */
333 s1
= s2
; /* expected-error {{cannot assign to variable 's1' with const-qualified data member 'i'}} */
337 * Reservation of macro names
341 /* FIXME: undefining a macro defined by the standard library is undefined
342 * behavior. We have diagnostics when declaring reserved identifiers, and we
343 * could consider extending that to undefining a macro defined in a system
344 * header. However, whether we diagnose or not, we conform.
350 * Preprocessing of preprocessing directives
353 # DR144 include <stddef.h> /* expected-error {{invalid preprocessing directive}} */
354 DR144
# include <stddef.h> /* expected-error {{expected identifier or '('}} */
357 * Constant expressions
360 static int array
[10];
361 static int *ip
= (int *)0;
362 /* The below is failing because some systems think this is a valid compile-
363 * time constant. Commenting the out while investigating whether we implement
364 * this DR properly or not.
365 * static int i = array[0] + array[1]; broken-expected-error {{initializer element is not a compile-time constant}}
370 * Initialization of a char array from a string literal
373 /* Accept even though a string literal is not a constant expression. */
374 static char array
[] = "Hello, World";
378 * Undeclared identifiers
382 i
= undeclared
; /* expected-error {{use of undeclared identifier 'undeclared'}} */
383 sdfsdfsf
= 1; /* expected-error {{use of undeclared identifier 'sdfsdfsf'}} */
384 i
= also_undeclared(); /* c99untilc2x-error {{call to undeclared function 'also_undeclared'; ISO C99 and later do not support implicit function declarations}}
385 c2xandup-error {{use of undeclared identifier 'also_undeclared'}}
393 int a
[][5]; /* expected-error {{definition of variable with array type needs an explicit size or an initializer}} */
394 int x
, b
[][5]; /* expected-error {{definition of variable with array type needs an explicit size or an initializer}} */