[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / C / drs / dr1xx.c
blob400807ed5da8422911785b2eb78c078167d7e558
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
6 */
8 /* The following are DRs which do not require tests to demonstrate
9 * conformance or nonconformance.
11 * WG14 DR100: dup 001
12 * Defect with the return statement
14 * WG14 DR104: dup 084
15 * Incomplete tag types in a parameter list
17 * WG14 DR109: yes
18 * Are undefined values and undefined behavior the same?
20 * WG14 DR110: dup 047
21 * Formal parameters having array-of-non-object types
23 * WG14 DR117: yes
24 * Abstract semantics, sequence points, and expression evaluation
26 * WG14 DR121: yes
27 * Conversions of pointer values to integral types
29 * WG14 DR122: dup 015
30 * Conversion/widening of bit-fields
32 * WG14 DR125: yes
33 * Using things declared as 'extern (qualified) void'
35 * WG14 DR127: dup 013
36 * Composite type of an enumerated type and an integral type
38 * WG14 DR132: dup 109
39 * Can undefined behavior occur at translation time, or only at run time?
41 * WG14 DR133: yes
42 * Undefined behavior not previously listed in subclause G2
44 * WG14 DR138: yes
45 * Is there an allocated storage duration?
47 * WG14 DR139: yes
48 * Compatibility of complete and incomplete types
50 * WG14 DR146: yes
51 * Nugatory constraint
53 * WG14 DR147: yes
54 * Sequence points in library functions
56 * WG14 DR148: yes
57 * Defining library functions
59 * WG14 DR149: yes
60 * The term "variable"
62 * WG14 DR154: yes
63 * Consistency of implementation-defined values
65 * WG14 DR159: yes
66 * Consistency of the C Standard Defects exist in the way the Standard refers
67 * to itself
69 * WG14 DR161: yes
70 * Details of reserved symbols
72 * WG14 DR169: yes
73 * Trigraphs
77 /* WG14 DR101: yes
78 * Type qualifiers and "as if by assignment"
80 void dr101_callee(const int val);
81 void dr101_caller(void) {
82 int val = 1;
83 dr101_callee(val); /* ok; const qualifier on the parameter doesn't prevent as-if assignment. */
86 /* WG14 DR102: yes
87 * Tag redeclaration constraints
89 void dr102(void) {
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'}} */
101 /* WG14 DR103: yes
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.
119 void dr105(void) {
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'}} */
133 /* WG14 DR106: yes
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 *'}}*/
157 /* WG14 DR108: yes
158 * Can a macro identifier hide a keyword?
160 void dr108(void) {
161 #define const
162 const int i = 12;
163 #undef const
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'}} */
170 /* WG14 DR111: yes
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}} */
177 /* WG14 DR112: yes
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);
187 /* WG14 DR113: yes
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 *'}} */
199 /* WG14 DR114: yes
200 * Initialization of multi-dimensional char array objects
202 void dr114(void) {
203 char array[2][5] = { "defghi" }; /* expected-warning {{initializer-string for char array is too long}} */
206 /* WG14 DR115: yes
207 * Member declarators as declarators
209 void dr115(void) {
210 struct { int mbr; }; /* expected-warning {{declaration does not declare anything}} */
211 union { int mbr; }; /* expected-warning {{declaration does not declare anything}} */
214 /* WG14 DR116: yes
215 * Implicit unary & applied to register arrays
217 void dr116(void) {
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}} */
224 /* WG14 DR118: yes
225 * Completion point for enumerated types
227 void dr118(void) {
228 enum E {
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.
237 Val = sizeof(enum E)
238 #ifndef _WIN32
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 '}'}} */
241 #endif
245 /* WG14 DR119: yes
246 * Initialization of multi-dimensional array objects
248 void dr119(void) {
249 static int array[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; /* expected-error {{array has incomplete element type 'int[]'}} */
252 /* WG14 DR120: yes
253 * Semantics of assignment to (and initialization of) bit-fields
255 void dr120(void) {
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}} */
262 struct S object2;
263 object2.bit = 3; /* expected-warning {{implicit truncation from 'int' to bit-field changes value from 3 to 1}} */
266 /* WG14 DR123: yes
267 * 'Type categories' and qualified types
269 void dr123(void) {
270 /* Both of these examples are strictly conforming. */
271 enum E1 {
272 enumerator1 = (const int) 9
274 enum E2 {
275 enumerator2 = (volatile int) 9
279 /* WG14 DR124: yes
280 * Casts to 'a void type' versus casts to 'the void type'
282 void dr124(void) {
283 /* A cast can cast to void or any qualified version of void. */
284 (const volatile void)0;
287 /* WG14 DR126: yes
288 * What does 'synonym' mean with respect to typedef names?
290 void dr126(void) {
291 typedef int *IP;
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')}} */
301 /* WG14 DR128: yes
302 * Editorial issue relating to tag declarations in type specifiers
304 void dr128(void) {
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'}}
315 /* WG14 DR129: yes
316 * Tags and name spaces
318 struct dr129_t { int i; };
319 void dr129(void) {
320 enum dr129_t { enumerator }; /* expected-note {{previous use is here}} */
321 void *vp;
323 (void)(struct dr129_t *)vp; /* expected-error {{use of 'dr129_t' with tag type that does not match previous declaration}} */
326 /* WG14 DR131: yes
327 * const member qualification and assignment
329 void dr131(void) {
330 struct S {
331 const int i; /* expected-note {{data member 'i' declared const here}} */
332 } s1, s2;
333 s1 = s2; /* expected-error {{cannot assign to variable 's1' with const-qualified data member 'i'}} */
336 /* WG14 DR142: yes
337 * Reservation of macro names
339 void dr142(void) {
340 #include <stddef.h>
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.
346 #undef NULL
349 /* WG14 DR144: yes
350 * Preprocessing of preprocessing directives
352 #define DR144
353 # DR144 include <stddef.h> /* expected-error {{invalid preprocessing directive}} */
354 DR144 # include <stddef.h> /* expected-error {{expected identifier or '('}} */
356 /* WG14 DR145:
357 * Constant expressions
359 void dr145(void) {
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}}
369 /* WG14 DR150: yes
370 * Initialization of a char array from a string literal
372 void dr150(void) {
373 /* Accept even though a string literal is not a constant expression. */
374 static char array[] = "Hello, World";
377 /* WG14 DR163: yes
378 * Undeclared identifiers
380 void dr163(void) {
381 int i;
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'}}
389 /* WG14 DR164: yes
390 * Bad declarations
392 void dr164(void) {
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}} */