396 lines · c
1/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only,untilc23 -pedantic -Wno-c11-extensions %s2 RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=expected,c99untilc2x,untilc23 -pedantic -Wno-c11-extensions %s3 RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x,untilc23 -pedantic %s4 RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x,untilc23 -pedantic %s5 RUN: %clang_cc1 -std=c23 -fsyntax-only -verify=expected,c2xandup -pedantic %s6 */7 8/* The following are DRs which do not require tests to demonstrate9 * conformance or nonconformance.10 *11 * WG14 DR100: dup 00112 * Defect with the return statement13 *14 * WG14 DR104: dup 08415 * Incomplete tag types in a parameter list16 *17 * WG14 DR109: yes18 * Are undefined values and undefined behavior the same?19 *20 * WG14 DR110: dup 04721 * Formal parameters having array-of-non-object types22 *23 * WG14 DR117: yes24 * Abstract semantics, sequence points, and expression evaluation25 *26 * WG14 DR121: yes27 * Conversions of pointer values to integral types28 *29 * WG14 DR122: dup 01530 * Conversion/widening of bit-fields31 *32 * WG14 DR125: yes33 * Using things declared as 'extern (qualified) void'34 *35 * WG14 DR127: dup 01336 * Composite type of an enumerated type and an integral type37 *38 * WG14 DR132: dup 10939 * Can undefined behavior occur at translation time, or only at run time?40 *41 * WG14 DR133: yes42 * Undefined behavior not previously listed in subclause G243 *44 * WG14 DR138: yes45 * Is there an allocated storage duration?46 *47 * WG14 DR139: yes48 * Compatibility of complete and incomplete types49 *50 * WG14 DR146: yes51 * Nugatory constraint52 *53 * WG14 DR147: yes54 * Sequence points in library functions55 *56 * WG14 DR148: yes57 * Defining library functions58 *59 * WG14 DR149: yes60 * The term "variable"61 *62 * WG14 DR154: yes63 * Consistency of implementation-defined values64 *65 * WG14 DR159: yes66 * Consistency of the C Standard Defects exist in the way the Standard refers67 * to itself68 *69 * WG14 DR161: yes70 * Details of reserved symbols71 *72 * WG14 DR169: yes73 * Trigraphs74 */75 76 77/* WG14 DR101: yes78 * Type qualifiers and "as if by assignment"79 */80void dr101_callee(const int val);81void dr101_caller(void) {82 int val = 1;83 dr101_callee(val); /* ok; const qualifier on the parameter doesn't prevent as-if assignment. */84}85 86/* WG14 DR102: yes87 * Tag redeclaration constraints88 */89void dr102(void) {90 struct S { int member; }; /* untilc23-note {{previous definition is here}} */91 struct S { int member; }; /* untilc23-error {{redefinition of 'S'}} */92 93 union U { int member; }; /* untilc23-note {{previous definition is here}} */94 union U { int member; }; /* untilc23-error {{redefinition of 'U'}} */95 96 enum E { member }; /* untilc23-note 2{{previous definition is here}} */97 enum E { member }; /* untilc23-error {{redefinition of 'E'}}98 untilc23-error {{redefinition of enumerator 'member'}} */99}100 101/* WG14 DR103: yes102 * Formal parameters of incomplete type103 */104void dr103_1(int arg[]); /* ok, not an incomplete type due to rewrite */105void 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'}} */108void 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}} */110void dr103_3(struct S { int a; } s) { } /* untilc23-warning {{declaration of 'struct S' will not be visible outside of this function}}111 expected-error {{conflicting types for 'dr103_3'}} */112void dr103_4(struct S s1, struct S { int a; } s2); /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}} */113 114/* WG14 DR105: dup 017115 * Precedence of requirements on compatible types116 *117 * NB: This is also Question 3 from DR017.118 */119void dr105(void) {120 /* According to C2x 6.7.6.3p14 the return type and parameter types to be121 * compatible types, but qualifiers are dropped from the parameter type.122 */123 extern void func(int);124 extern void func(const int); /* FIXME: this should be pedantically diagnosed. */125 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'}} */128 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'}} */131}132 133/* WG14 DR106: yes134 * When can you dereference a void pointer?135 *136 * NB: This is a partial duplicate of DR012.137 */138void 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 *'}} */142 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 *'}}*/145 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 *'}}*/148 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 *'}}*/151 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 *'}}*/155}156 157/* WG14 DR108: yes158 * Can a macro identifier hide a keyword?159 */160void dr108(void) {161#define const162 const int i = 12;163#undef const164 const int j = 12; /* expected-note {{variable 'j' declared const here}} */165 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'}} */168}169 170/* WG14 DR111: yes171 * Conversion of pointer-to-qualified type values to type (void*) values172 */173void dr111(const char *ccp, void *vp) {174 vp = ccp; /* expected-warning {{assigning to 'void *' from 'const char *' discards qualifiers}} */175}176 177/* WG14 DR112: yes178 * Null pointer constants and relational comparisons179 */180void dr112(void *vp) {181 /* The behavior of this expression is pedantically undefined.182 * FIXME: should we diagnose under -pedantic?183 */184 (void)(vp > (void*)0);185}186 187/* WG14 DR113: yes188 * Return expressions in functions declared to return qualified void189 */190volatile 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 *'}} */193}194const 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 *'}} */197}198 199/* WG14 DR114: yes200 * Initialization of multi-dimensional char array objects201 */202void dr114(void) {203 char array[2][5] = { "defghi" }; /* expected-warning {{initializer-string for char array is too long}} */204}205 206/* WG14 DR115: yes207 * Member declarators as declarators208 */209void dr115(void) {210 struct { int mbr; }; /* expected-warning {{declaration does not declare anything}} */211 union { int mbr; }; /* expected-warning {{declaration does not declare anything}} */212}213 214/* WG14 DR116: yes215 * Implicit unary & applied to register arrays216 */217void 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}} */222}223 224/* WG14 DR118: yes225 * Completion point for enumerated types226 */227void dr118(void) {228 enum E {229 /* The enum isn't a complete type until the closing }, but an230 * implementation may complete the type earlier if it has sufficient type231 * information to calculate size or alignment, etc.232 *233 * On Microsoft targets, an enum is always implicit int sized, so the type234 * is sufficiently complete there. On other platforms, it is an incomplete235 * type at this point.236 */237 Val = sizeof(enum E)238 #if !defined(_WIN32) || defined(__MINGW32__)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 #endif242 };243}244 245/* WG14 DR119: yes246 * Initialization of multi-dimensional array objects247 */248void dr119(void) {249 static int array[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; /* expected-error {{array has incomplete element type 'int[]'}} */250}251 252/* WG14 DR120: yes253 * Semantics of assignment to (and initialization of) bit-fields254 */255void dr120(void) {256 /* We could verify this one with a codegen test to ensure that the proper257 * value is stored into bit, but the diagnostic tells us what the value is258 * after conversion, so we can lean on that for verification.259 */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}} */264}265 266/* WG14 DR123: yes267 * 'Type categories' and qualified types268 */269void dr123(void) {270 /* Both of these examples are strictly conforming. */271 enum E1 {272 enumerator1 = (const int) 9273 };274 enum E2 {275 enumerator2 = (volatile int) 9276 };277}278 279/* WG14 DR124: yes280 * Casts to 'a void type' versus casts to 'the void type'281 */282void dr124(void) {283 /* A cast can cast to void or any qualified version of void. */284 (const volatile void)0;285}286 287/* WG14 DR126: yes288 * What does 'synonym' mean with respect to typedef names?289 */290void dr126(void) {291 typedef int *IP;292 const IP object = 0; /* expected-note {{variable 'object' declared const here}} */293 294 /* The root of the DR is whether 'object' is a pointer to a const int, or a295 * const pointer to int.296 */297 *object = 12; /* ok */298 ++object; /* expected-error {{cannot assign to variable 'object' with const-qualified type 'const IP' (aka 'int *const')}} */299}300 301/* WG14 DR128: yes302 * Editorial issue relating to tag declarations in type specifiers303 */304void dr128(void) {305 {306 struct TAG { int i; };307 }308 {309 struct TAG object; /* expected-error {{variable has incomplete type 'struct TAG'}}310 expected-note {{forward declaration of 'struct TAG'}}311 */312 }313}314 315/* WG14 DR129: yes316 * Tags and name spaces317 */318struct dr129_t { int i; };319void dr129(void) {320 enum dr129_t { enumerator }; /* expected-note {{previous use is here}} */321 void *vp;322 323 (void)(struct dr129_t *)vp; /* expected-error {{use of 'dr129_t' with tag type that does not match previous declaration}} */324}325 326/* WG14 DR131: yes327 * const member qualification and assignment328 */329void dr131(void) {330 struct S {331 const int i; /* expected-note {{data member 'i' declared const here}} */332 } s1 = { 0 }, s2 = { 0 };333 s1 = s2; /* expected-error {{cannot assign to variable 's1' with const-qualified data member 'i'}} */334}335 336/* WG14 DR142: yes337 * Reservation of macro names338 */339void dr142(void) {340#include <stddef.h>341/* FIXME: undefining a macro defined by the standard library is undefined342 * behavior. We have diagnostics when declaring reserved identifiers, and we343 * could consider extending that to undefining a macro defined in a system344 * header. However, whether we diagnose or not, we conform.345 */346#undef NULL347}348 349/* WG14 DR144: yes350 * Preprocessing of preprocessing directives351 */352#define DR144353# DR144 include <stddef.h> /* expected-error {{invalid preprocessing directive}} */354DR144 # include <stddef.h> /* expected-error {{expected identifier or '('}} */355 356/* WG14 DR145:357 * Constant expressions358 */359void 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 implement364 * this DR properly or not.365 * static int i = array[0] + array[1]; broken-expected-error {{initializer element is not a compile-time constant}}366 */367}368 369/* WG14 DR150: yes370 * Initialization of a char array from a string literal371 */372void dr150(void) {373 /* Accept even though a string literal is not a constant expression. */374 static char array[] = "Hello, World";375}376 377/* WG14 DR163: yes378 * Undeclared identifiers379 */380void 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'}}386 */387}388 389/* WG14 DR164: yes390 * Bad declarations391 */392void 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}} */395}396