File: n3409.c

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (57 lines) | stat: -rw-r--r-- 2,738 bytes parent folder | download | duplicates (3)
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
// RUN: %clang_cc1 -verify -std=c2y -pedantic -Wno-unused %s
// RUN: %clang_cc1 -verify=expected,pre-c2y -std=c2y -Wpre-c2y-compat -Wno-unused %s
// RUN: %clang_cc1 -verify=expected,ext -std=c23 -pedantic -Wno-unused %s

/* WG14 N3409: Clang 21
 * Slay Some Earthly Demons X
 *
 * Removes the requirement that an expression with type void cannot be used in
 * any way. This was making it UB to use a void expression in a _Generic
 * selection expression for no good reason, as well as making it UB to cast a
 * void expression to void, etc.
 */

extern void x;
void foo() {
  // FIXME: this is technically an extension before C2y and should be diagnosed
  // under -pedantic.
  (void)(void)1;
  // FIXME: same with this.
  x;
  _Generic(x, void: 1);      /* pre-c2y-warning {{use of incomplete type 'void' in a '_Generic' association is incompatible with C standards before C2y}}
                                ext-warning {{incomplete type 'void' in a '_Generic' association is a C2y extension}}
                              */
  _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}}
                                ext-warning {{incomplete type 'typeof (x)' (aka 'void') in a '_Generic' association is a C2y extension}}
                              */
  (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}}
                                        ext-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
                                      */

  // This is not sufficiently important of an extension to warrant a "not
  // compatible with standards before C2y" warning, but it is an extension in
  // C23 and earlier.
  return x; // ext-warning {{void function 'foo' should not return void expression}}
}


// Ensure we behave correctly with incomplete types. See GH141549.
static_assert(
  _Generic(
    void,    /* ext-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
                pre-c2y-warning {{passing a type argument as the first operand to '_Generic' is incompatible with C standards before C2y}}
              */
    void : 1,
    default : 0
  )
);

static_assert(
  _Generic( // expected-error {{static assertion failed}}
    12,
    void : 1, /* ext-warning {{incomplete type 'void' in a '_Generic' association is a C2y extension}}
                 pre-c2y-warning {{use of incomplete type 'void' in a '_Generic' association is incompatible with C standards before C2y}}
               */
    default : 0
  )
);