Debian Codegraph @

clang/test/C/C2y/n3409.c

raw
1 // RUN: %clang_cc1 -verify -std=c2y -pedantic -Wno-unused %s
2 // RUN: %clang_cc1 -verify=expected,pre-c2y -std=c2y -Wpre-c2y-compat -Wno-unused %s
3 // RUN: %clang_cc1 -verify=expected,ext -std=c23 -pedantic -Wno-unused %s
4
5 /* WG14 N3409: Clang 21
6 * Slay Some Earthly Demons X
7 *
8 * Removes the requirement that an expression with type void cannot be used in
9 * any way. This was making it UB to use a void expression in a _Generic
10 * selection expression for no good reason, as well as making it UB to cast a
11 * void expression to void, etc.
12 */
13
14 extern void x;
15 void foo() {
16 // FIXME: this is technically an extension before C2y and should be diagnosed
17 // under -pedantic.
18 (void)(void)1;
19 // FIXME: same with this.
20 x;
21 _Generic(x, void: 1); /* pre-c2y-warning {{use of incomplete type 'void' in a '_Generic' association is incompatible with C standards before C2y}}
22 ext-warning {{incomplete type 'void' in a '_Generic' association is a C2y extension}}
23 */
24 _Generic(x, typeof(x): 1); /* pre-c2y-warning {{use of incomplete type 'typeof (x)' (aka 'void') in a '_Generic' association is incompatible with C standards before C2y}}
25 ext-warning {{incomplete type 'typeof (x)' (aka 'void') in a '_Generic' association is a C2y extension}}
26 */
27 (void)_Generic(void, default : 1); /* pre-c2y-warning {{passing a type argument as the first operand to '_Generic' is incompatible with C standards before C2y}}
28 ext-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
29 */
30
31 // This is not sufficiently important of an extension to warrant a "not
32 // compatible with standards before C2y" warning, but it is an extension in
33 // C23 and earlier.
34 return x; // ext-warning {{void function 'foo' should not return void expression}}
35 }
36
37
38 // Ensure we behave correctly with incomplete types. See GH141549.
39 static_assert(
40 _Generic(
41 void, /* ext-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
42 pre-c2y-warning {{passing a type argument as the first operand to '_Generic' is incompatible with C standards before C2y}}
43 */
44 void : 1,
45 default : 0
46 )
47 );
48
49 static_assert(
50 _Generic( // expected-error {{static assertion failed}}
51 12,
52 void : 1, /* ext-warning {{incomplete type 'void' in a '_Generic' association is a C2y extension}}
53 pre-c2y-warning {{use of incomplete type 'void' in a '_Generic' association is incompatible with C standards before C2y}}
54 */
55 default : 0
56 )
57 );