brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · a0b8e2f Raw
58 lines · c
1// RUN: %clang_cc1 -verify -std=c2y -pedantic -Wno-unused %s2// RUN: %clang_cc1 -verify=expected,pre-c2y -std=c2y -Wpre-c2y-compat -Wno-unused %s3// RUN: %clang_cc1 -verify=expected,ext -std=c23 -pedantic -Wno-unused %s4 5/* WG14 N3409: Clang 216 * Slay Some Earthly Demons X7 *8 * Removes the requirement that an expression with type void cannot be used in9 * any way. This was making it UB to use a void expression in a _Generic10 * selection expression for no good reason, as well as making it UB to cast a11 * void expression to void, etc.12 */13 14extern void x;15void foo() {16  // FIXME: this is technically an extension before C2y and should be diagnosed17  // 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 "not32  // compatible with standards before C2y" warning, but it is an extension in33  // 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.39static_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 : 046  )47);48 49static_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 : 056  )57);58