File: dr3xx.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (301 lines) | stat: -rw-r--r-- 12,067 bytes parent folder | download | duplicates (8)
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
/* RUN: %clang_cc1 -std=c89 -fsyntax-only -Wvla -verify=expected,c89only,c17andearlier -pedantic -Wno-c11-extensions %s
   RUN: %clang_cc1 -std=c99 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic -Wno-c11-extensions %s
   RUN: %clang_cc1 -std=c11 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s
   RUN: %clang_cc1 -std=c17 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s
   RUN: %clang_cc1 -std=c2x -fsyntax-only -Wvla -verify=expected,c99andup,c23andup -pedantic %s
 */

/* The following are DRs which do not require tests to demonstrate
 * conformance or nonconformance.
 *
 * WG14 DR300: yes
 * Translation-time expresssion evaluation
 *
 * WG14 DR301: yes
 * Meaning of FE_* macros in <fenv.h>
 *
 * WG14 DR303: yes
 * Breaking up the very long sentence describing preprocessing directive
 *
 * WG14 DR307: yes
 * Clarifiying arguments vs. parameters
 *
 * WG14 DR308: yes
 * Clarify that source files et al. need not be "files"
 *
 * WG14 DR310: yes
 * Add non-corner case example of trigraphs
 *
 * WG14 DR312: yes
 * Meaning of "known constant size"
 *
 * WG14 DR333: yes
 * Missing Predefined Macro Name
 *
 * WG14 DR342: dup 340
 * VLAs and conditional expressions
 */


/* WG14 DR302: yes
 * Adding underscore to portable include file name character set
 */
#include "./abc_123.h"
#ifndef WE_SUPPORT_DR302
#error "Oh no, we don't support DR302 after all!"
#endif

/* WG14 DR304: yes
 * Clarifying illegal tokens in #if directives
 */
/* expected-error@+3 {{invalid token at start of a preprocessor expression}}
   expected-warning@+3 {{missing terminating ' character}}
 */
#if 'test
#endif

/* WG14 DR305: yes
 * Clarifying handling of keywords in #if directives
 */
#if int
#error "We definitely should not have gotten here"
#endif

/* WG14 DR306: yes
 * Clarifying that rescanning applies to object-like macros
 */
#define REPLACE 1
#define THIS REPLACE
#if THIS != 1
#error "We definitely should not have gotten here"
#endif

/* WG14 DR311: yes
 * Definition of variably modified types
 */
void dr311(int x) {
  typedef int vla[x]; /* expected-warning {{variable length array}} */

  /* Ensure that a constant array of variable-length arrays are still
   * considered a variable-length array.
   */
  vla y[3]; /* expected-warning {{variable length array}} */
}

/* WG14 DR313: yes
 * Incomplete arrays of VLAs
 */
void dr313(int i) {
  int c[][i] = { 0 }; /* expected-error {{variable-sized object may not be initialized}}
                         expected-warning {{variable length array}}
                       */
}

/* WG14 DR315: yes
 * Implementation-defined bit-field types
 */
struct dr315_t {
  unsigned long long a : 37; /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
  unsigned long long b : 37; /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */

  short c : 8;
  short d : 8;
} dr315;
_Static_assert(sizeof(dr315.a + dr315.b) == sizeof(unsigned long long), ""); /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
/* Demonstrate that integer promotions still happen when less than the width of
 * an int.
 */
_Static_assert(sizeof(dr315.c + dr315.d) == sizeof(int), "");

#if __STDC_VERSION__ < 202311L
/* WG14 DR316: yes
 * Unprototyped function types
 */
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}} */
void (*dr316_1_ptr)(int, int, int) = dr316_1;

/* WG14 DR317: yes
 * Function definitions with empty parentheses
 *
 * Despite the function with empty parens being a definition, this does not
 * provide a prototype for the function. However, calling the function with
 * arguments is undefined behavior, so it is defensible for us to warn the user
 * about it. They key point to this DR is that we give the "without a
 * prototype" warnings to demonstrate we don't give this function a prototype.
 */
void dr317_1() {}  /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */
void dr317_2(void) {
  if (0)
    dr317_1(1); /* expected-warning {{too many arguments in call to 'dr317_1'}}
                   expected-warning {{passing arguments to 'dr317_1' without a prototype is deprecated in all versions of C and is not supported in C23}}
                 */
}
#endif /* __STDC_VERSION__ < 202311L */

/* WG14 DR320: yes
 * Scope of variably modified type
 */
int dr320_v;
typedef int dr320_t[dr320_v]; /* c89only-warning {{variable length arrays are a C99 feature}}
                                 expected-error {{variable length array declaration not allowed at file scope}}
                                 c99andup-warning {{variable length array used}}
                               */
void dr320(int okay[dr320_v]) { /* c89only-warning {{variable length arrays are a C99 feature}}
                                   c99andup-warning {{variable length array used}}
                                 */
  typedef int type[dr320_v]; /* c89only-warning {{variable length arrays are a C99 feature}}
                                c99andup-warning {{variable length array used}}
                              */
  extern type bad;  /* expected-error {{variable length array declaration cannot have 'extern' linkage}} */

  /* C99 6.7.5.2p2, second sentence. */
  static type fine; /* expected-error {{variable length array declaration cannot have 'static' storage duration}} */
}

/* WG14 DR321: yes
 * Wide character code values for members of the basic character set
 */
#define DR321 (\
    ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' &&           \
    '\n' == L'\n' &&                                                            \
    'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' &&  \
    'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' &&  \
    'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' &&  \
    'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' &&  \
    'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' &&  \
    'z' == L'z' &&                                                              \
    'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' &&  \
    'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' &&  \
    'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' &&  \
    'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' &&  \
    'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' &&  \
    'Z' == L'Z' &&                                                              \
    '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' &&  \
    '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' &&                 \
    '9' == L'9' &&                                                              \
    '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' &&  \
    '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' &&  \
    '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' &&  \
    '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' &&  \
    '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' &&  \
    ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\''                \
  )
#if __STDC_MB_MIGHT_NEQ_WC__
#ifndef __FreeBSD__ /* PR22208, FreeBSD expects us to give a bad (but conforming) answer here. */
_Static_assert(!DR321, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation");
#endif
#else
_Static_assert(DR321, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs");
#endif

/* WG14 DR328: partial
 * String literals in compound literal initialization
 *
 * DR328 is implemented properly in terms of allowing string literals, but is
 * not implemented. See DR339 (marked as a duplicate of this one) for details.
 */
const char *dr328_v = (const char *){"this is a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */
void dr328(void) {
  const char *val = (const char *){"also a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */
}

/* WG14 DR335: yes
 * _Bool bit-fields
 *
 * See dr335.c also, which tests the runtime behavior of the part of the DR
 * which will compile.
 */
void dr335(void) {
  struct bits_ {
    _Bool bbf3 : 3; /* expected-error {{width of bit-field 'bbf3' (3 bits) exceeds the width of its type (1 bit)}}
                       c89only-warning {{'_Bool' is a C99 extension}}
                     */
  };
}

/* WG14 DR339: dup 328
 * Variably modified compound literals
 *
 * This DR is marked as a duplicate of DR328, see that DR for further
 * details.
 *
 * FIXME: we should be diagnosing this compound literal as creating a variably-
 * modified type at file scope, as we would do for a file scope variable.
 */
extern int dr339_v;
void *dr339 = &(int (*)[dr339_v]){ 0 }; /* c89only-warning {{variable length arrays are a C99 feature}}
                                           c99andup-warning {{variable length array used}}
                                           c89only-warning {{compound literals are a C99-specific feature}}
                                         */

/* WG14 DR340: yes
 * Composite types for variable-length arrays
 *
 * The DR made this behavior undefined because implementations disagreed on the
 * behavior. For this DR, Clang accepts the code and GCC rejects it. It's
 * unclear whether the Clang behavior is intentional, but because the code is
 * UB, any behavior is acceptable.
 */
#if __STDC_VERSION__ < 202311L
void dr340(int x, int y) {
  typedef void (*T1)(int);
  typedef void (*T2)(); /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */

  T1 (*a)[] = 0;
  T2 (*b)[x] = 0;       /* c89only-warning {{variable length arrays are a C99 feature}}
                           c99andup-warning {{variable length array used}}
                         */
  (y ? a : b)[0][0]();
}
#endif /* __STDC_VERSION__ < 202311L */

/* WG14 DR341: yes
 * [*] in abstract declarators
 */
void dr341_1(int (*)[*]);                  /* c89only-warning {{variable length arrays are a C99 feature}}
                                              c99andup-warning {{variable length array used}}
                                            */
void dr341_2(int (*)[sizeof(int (*)[*])]); /* expected-error {{star modifier used outside of function prototype}} */

/* WG14 DR343: yes
 * Initializing qualified wchar_t arrays
 */
void dr343(void) {
  const __WCHAR_TYPE__ x[] = L"foo";
}

/* WG14 DR344: yes
 * Casts in preprocessor conditional expressions
 *
 * Note: this DR removed a constraint about not containing casts because there
 * are no keywords, therefore no types to cast to, so casts simply don't exist
 * as a construct during preprocessing.
 */
#if (int)+0
#error "this should not be an error, we shouldn't get here"
#else
/* expected-error@+1 {{"reached"}} */
#error "reached"
#endif

/* WG14 DR345: yes
 * Where does parameter scope start?
 */
void f(long double f,
       char (**a)[10 * sizeof f]) {
  _Static_assert(sizeof **a == sizeof(long double) * 10, "");
}

/* WG14 DR309: yes
 * Clarifying trigraph substitution
 */
int dr309??(1??) = { 1 }; /* c17andearlier-warning {{trigraph converted to '[' character}}
                             c17andearlier-warning {{trigraph converted to ']' character}}
                             c23andup-warning 2 {{trigraph ignored}}
                             c23andup-error {{expected ';' after top level declarator}}
                           */

/* NOTE: Due to interactions with the diagnostic system, dr309 should be the
 * last test case in this file because subsequent diagnostics may not be
 * generated as expected.
 */