File: dr1xx.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (383 lines) | stat: -rw-r--r-- 13,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-c11-extensions %s
   RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
   RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
   RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
   RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic %s
 */

/* The following are DRs which do not require tests to demonstrate
 * conformance or nonconformance.
 *
 * WG14 DR100: dup 001
 * Defect with the return statement
 *
 * WG14 DR104: dup 084
 * Incomplete tag types in a parameter list
 *
 * WG14 DR109: yes
 * Are undefined values and undefined behavior the same?
 *
 * WG14 DR110: dup 047
 * Formal parameters having array-of-non-object types
 *
 * WG14 DR117: yes
 * Abstract semantics, sequence points, and expression evaluation
 *
 * WG14 DR121: yes
 * Conversions of pointer values to integral types
 *
 * WG14 DR122: dup 015
 * Conversion/widening of bit-fields
 *
 * WG14 DR125: yes
 * Using things declared as 'extern (qualified) void'
 *
 * WG14 DR127: dup 013
 * Composite type of an enumerated type and an integral type
 *
 * WG14 DR132: dup 109
 * Can undefined behavior occur at translation time, or only at run time?
 *
 * WG14 DR133: yes
 * Undefined behavior not previously listed in subclause G2
 *
 * WG14 DR138: yes
 * Is there an allocated storage duration?
 *
 * WG14 DR139: yes
 * Compatibility of complete and incomplete types
 *
 * WG14 DR146: yes
 * Nugatory constraint
 *
 * WG14 DR147: yes
 * Sequence points in library functions
 *
 * WG14 DR148: yes
 * Defining library functions
 *
 * WG14 DR149: yes
 * The term "variable"
 *
 * WG14 DR154: yes
 * Consistency of implementation-defined values
 *
 * WG14 DR159: yes
 * Consistency of the C Standard Defects exist in the way the Standard refers
 * to itself
 *
 * WG14 DR161: yes
 * Details of reserved symbols
 *
 * WG14 DR169: yes
 * Trigraphs
 */


/* WG14 DR101: yes
 * Type qualifiers and "as if by assignment"
 */
void dr101_callee(const int val);
void dr101_caller(void) {
  int val = 1;
  dr101_callee(val); /* ok; const qualifier on the parameter doesn't prevent as-if assignment. */
}

/* WG14 DR102: yes
 * Tag redeclaration constraints
 */
void dr102(void) {
  struct S { int member; }; /* expected-note {{previous definition is here}} */
  struct S { int member; }; /* expected-error {{redefinition of 'S'}} */

  union U { int member; }; /* expected-note {{previous definition is here}} */
  union U { int member; }; /* expected-error {{redefinition of 'U'}} */

  enum E { member }; /* expected-note 2{{previous definition is here}} */
  enum E { member }; /* expected-error {{redefinition of 'E'}}
                        expected-error {{redefinition of enumerator 'member'}} */
}

/* WG14 DR103: yes
 * Formal parameters of incomplete type
 */
void dr103_1(int arg[]); /* ok, not an incomplete type due to rewrite */
void dr103_2(struct S s) {} /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
                               expected-error {{variable has incomplete type 'struct S'}}
                               expected-note {{forward declaration of 'struct S'}} */
void dr103_3(struct S s);               /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
                                           expected-note {{previous declaration is here}} */
void dr103_3(struct S { int a; } s) { } /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
                                           expected-error {{conflicting types for 'dr103_3'}} */
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}} */

/* WG14 DR105: dup 017
 * Precedence of requirements on compatible types
 *
 * NB: This is also Question 3 from DR017.
 */
void dr105(void) {
  /* According to C2x 6.7.6.3p14 the return type and parameter types to be
   * compatible types, but qualifiers are dropped from the parameter type.
   */
  extern void func(int);
  extern void func(const int); /* FIXME: this should be pedantically diagnosed. */

  extern void other_func(int);   /* expected-note {{previous declaration is here}} */
  extern void other_func(int *); /* expected-error {{conflicting types for 'other_func'}} */

  extern int i;   /* expected-note {{previous declaration is here}} */
  extern float i; /* expected-error {{redeclaration of 'i' with a different type: 'float' vs 'int'}} */
}

/* WG14 DR106: yes
 * When can you dereference a void pointer?
 *
 * NB: This is a partial duplicate of DR012.
 */
void dr106(void *p, int i) {
  /* The behavior changed between C89 and C99. */
  (void)&*p; /* c89only-warning {{ISO C forbids taking the address of an expression of type 'void'}} */
  /* The behavior of all three of these is undefined. */
  (void)*p;
  (void)(i ? *p : *p);
  (void)(*p, *p); /* expected-warning {{left operand of comma operator has no effect}} */
}

/* WG14 DR108: yes
 * Can a macro identifier hide a keyword?
 */
void dr108(void) {
#define const
  const int i = 12;
#undef const
  const int j = 12; /* expected-note {{variable 'j' declared const here}} */

  i = 100; /* Okay, the keyword was hidden by the macro. */
  j = 100; /* expected-error {{cannot assign to variable 'j' with const-qualified type 'const int'}} */
}

/* WG14 DR111: yes
 * Conversion of pointer-to-qualified type values to type (void*) values
 */
void dr111(const char *ccp, void *vp) {
  vp = ccp; /* expected-warning {{assigning to 'void *' from 'const char *' discards qualifiers}} */
}

/* WG14 DR112: yes
 * Null pointer constants and relational comparisons
 */
void dr112(void *vp) {
  /* The behavior of this expression is pedantically undefined.
   * FIXME: should we diagnose under -pedantic?
   */
  (void)(vp > (void*)0);
}

/* WG14 DR113: yes
 * Return expressions in functions declared to return qualified void
 */
volatile void dr113_v(volatile void *vvp) { /* expected-warning {{function cannot return qualified void type 'volatile void'}} */
  return *vvp; /* expected-warning {{void function 'dr113_v' should not return void expression}} */
}
const void dr113_c(const void *cvp) { /* expected-warning {{function cannot return qualified void type 'const void'}} */
  return *cvp; /* expected-warning {{void function 'dr113_c' should not return void expression}} */
}

/* WG14 DR114: yes
 * Initialization of multi-dimensional char array objects
 */
void dr114(void) {
  char array[2][5] = { "defghi" }; /* expected-warning {{initializer-string for char array is too long}} */
}

/* WG14 DR115: yes
 * Member declarators as declarators
 */
void dr115(void) {
  struct { int mbr; }; /* expected-warning {{declaration does not declare anything}} */
  union { int mbr; };  /* expected-warning {{declaration does not declare anything}} */
}

/* WG14 DR116: yes
 * Implicit unary & applied to register arrays
 */
void dr116(void) {
  register int array[5] = { 0, 1, 2, 3, 4 };
  (void)array;       /* expected-error {{address of register variable requested}} */
  (void)array[3];    /* expected-error {{address of register variable requested}} */
  (void)(array + 3); /* expected-error {{address of register variable requested}} */
}

/* WG14 DR118: yes
 * Completion point for enumerated types
 */
void dr118(void) {
  enum E {
	/* The enum isn't a complete type until the closing }, but an
	 * implementation may complete the type earlier if it has sufficient type
	 * information to calculate size or alignment, etc.
	 *
	 * On Microsoft targets, an enum is always implicit int sized, so the type
	 * is sufficiently complete there. On other platforms, it is an incomplete
	 * type at this point.
	 */
    Val = sizeof(enum E)
    #ifndef _WIN32
    /* expected-error@-2 {{invalid application of 'sizeof' to an incomplete type 'enum E'}} */
    /* expected-note@-12 {{definition of 'enum E' is not complete until the closing '}'}} */
    #endif
  };
}

/* WG14 DR119: yes
 * Initialization of multi-dimensional array objects
 */
void dr119(void) {
  static int array[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; /* expected-error {{array has incomplete element type 'int[]'}} */
}

/* WG14 DR120: yes
 * Semantics of assignment to (and initialization of) bit-fields
 */
void dr120(void) {
  /* We could verify this one with a codegen test to ensure that the proper
   * value is stored into bit, but the diagnostic tells us what the value is
   * after conversion, so we can lean on that for verification.
   */
  struct S { unsigned bit:1; };
  struct S object1 = { 3 }; /* expected-warning {{implicit truncation from 'int' to bit-field changes value from 3 to 1}} */
  struct S object2;
  object2.bit = 3; /* expected-warning {{implicit truncation from 'int' to bit-field changes value from 3 to 1}} */
}

/* WG14 DR123: yes
 * 'Type categories' and qualified types
 */
void dr123(void) {
  /* Both of these examples are strictly conforming. */
  enum E1 {
    enumerator1 = (const int) 9
  };
  enum E2 {
    enumerator2 = (volatile int) 9
  };
}

/* WG14 DR124: yes
 * Casts to 'a void type' versus casts to 'the void type'
 */
void dr124(void) {
  /* A cast can cast to void or any qualified version of void. */
  (const volatile void)0;
}

/* WG14 DR126:  yes
 * What does 'synonym' mean with respect to typedef names?
 */
void dr126(void) {
  typedef int *IP;
  const IP object; /* expected-note {{variable 'object' declared const here}} */

  /* The root of the DR is whether 'object' is a pointer to a const int, or a
   * const pointer to int.
   */
  *object = 12; /* ok */
  ++object; /* expected-error {{cannot assign to variable 'object' with const-qualified type 'const IP' (aka 'int *const')}} */
}

/* WG14 DR128: yes
 * Editorial issue relating to tag declarations in type specifiers
 */
void dr128(void) {
  {
    struct TAG { int i; };
  }
  {
    struct TAG object; /* expected-error {{variable has incomplete type 'struct TAG'}}
                          expected-note {{forward declaration of 'struct TAG'}}
                        */
  }
}

/* WG14 DR129: yes
 * Tags and name spaces
 */
struct dr129_t { int i; };
void dr129(void) {
  enum dr129_t { enumerator }; /* expected-note {{previous use is here}} */
  void *vp;

  (void)(struct dr129_t *)vp; /* expected-error {{use of 'dr129_t' with tag type that does not match previous declaration}} */
}

/* WG14 DR131: yes
 * const member qualification and assignment
 */
void dr131(void) {
  struct S {
    const int i; /* expected-note {{data member 'i' declared const here}} */
  } s1, s2;
  s1 = s2; /* expected-error {{cannot assign to variable 's1' with const-qualified data member 'i'}} */
}

/* WG14 DR142: yes
 * Reservation of macro names
 */
void dr142(void) {
#include <stddef.h>
/* FIXME: undefining a macro defined by the standard library is undefined
 * behavior. We have diagnostics when declaring reserved identifiers, and we
 * could consider extending that to undefining a macro defined in a system
 * header. However, whether we diagnose or not, we conform.
 */
#undef NULL
}

/* WG14 DR144: yes
 * Preprocessing of preprocessing directives
 */
#define DR144
# DR144 include <stddef.h> /* expected-error {{invalid preprocessing directive}} */
DR144 # include <stddef.h> /* expected-error {{expected identifier or '('}} */

/* WG14 DR145:
 * Constant expressions
 */
void dr145(void) {
  static int array[10];
  static int *ip = (int *)0;
  /* The below is failing because some systems think this is a valid compile-
   * time constant. Commenting the out while investigating whether we implement
   * this DR properly or not.
   * static int i = array[0] + array[1]; broken-expected-error {{initializer element is not a compile-time constant}}
   */
}

/* WG14 DR150: yes
 * Initialization of a char array from a string literal
 */
void dr150(void) {
  /* Accept even though a string literal is not a constant expression. */
  static char array[] = "Hello, World";
}

/* WG14 DR163: yes
 * Undeclared identifiers
 */
void dr163(void) {
  int i;
  i = undeclared; /* expected-error {{use of undeclared identifier 'undeclared'}} */
  sdfsdfsf = 1;   /* expected-error {{use of undeclared identifier 'sdfsdfsf'}} */
  i = also_undeclared(); /* c99untilc2x-warning {{call to undeclared function 'also_undeclared'; ISO C99 and later do not support implicit function declarations}}
                            c2xandup-error {{use of undeclared identifier 'also_undeclared'}}
                          */
}

/* WG14 DR164: yes
 * Bad declarations
 */
void dr164(void) {
  int a [][5];    /* expected-error {{definition of variable with array type needs an explicit size or an initializer}} */
  int x, b [][5]; /* expected-error {{definition of variable with array type needs an explicit size or an initializer}} */
}