brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 158d7e3 Raw
84 lines · c
1// RUN: %clang_cc1 -std=c2y %s -verify -Wno-gnu-alignof-expression2 3/* WG14 N3244: Partial4 * Slay Some Earthly Demons I5 *6 * NB: the committee adopted:7 *   Annex J Item 21 (including additional change) -- no, we lack explicit documentation8 *   Annex J Item 56 -- yes9 *   Annex J Item 57 Option 1 -- yes10 *   Annex J Item 67 -- no11 *   Annex J Item 69 (alternative wording for semantics) -- no12 */13 14void reg_array(void) {15  // Decay of an array with the register storage class specifier has gone from16  // explicit undefined behavior to be implementation defined instead. Clang17  // does not support this.18  register int array[10];19  (void)sizeof(array); // okay20  int *vp = array;    // expected-error {{address of register variable requested}}21  int val = array[0]; // expected-error {{address of register variable requested}}22}23 24struct F;  // expected-note {{forward declaration of 'struct F'}}25void incomplete_no_linkage(struct F); // okay26void incomplete_no_linkage(struct F f) { // expected-error {{variable has incomplete type 'struct F'}}27  struct G g; // expected-error {{variable has incomplete type 'struct G'}} \28                 expected-note {{forward declaration of 'struct G'}}29  int i[];    // expected-error {{definition of variable with array type needs an explicit size or an initializer}}30}31 32void block_scope_non_extern_func_decl(void) {33  static void f(void); // expected-error {{function declared in block scope cannot have 'static' storage class}}34  extern void g(void); // okay35  __private_extern__ void h(void); // okay36}37 38// FIXME: this function should be diagnosed as it is never defined in the TU.39extern inline void never_defined_extern_inline(void);40 41// While this declaration is fine because the function is defined within the TU.42extern inline void is_defined_extern_inline(void);43extern inline void is_defined_extern_inline(void) {}44 45int NoAlignmentOnOriginalDecl;46// FIXME: the original declaration has no alignment specifier, so the47// declaration below should be diagnosed due to the incompatible alignment48// specifier.49_Alignas(8) int NoAlignmentOnOriginalDecl;50_Static_assert(_Alignof(NoAlignmentOnOriginalDecl) == 8, "");51 52_Alignas(8) int AlignmentOnOriginalDecl; // expected-note {{declared with '_Alignas' attribute here}}53// FIXME: this should be accepted because the redeclaration has no alignment54// specifier.55int AlignmentOnOriginalDecl; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}56_Static_assert(_Alignof(AlignmentOnOriginalDecl) == 8, "");57 58long long CompatibleAlignment;59_Static_assert(_Alignof(__typeof__(CompatibleAlignment)) == _Alignof(long long), "");60_Alignas(_Alignof(long long)) long long CompatibleAlignment; // Okay, alignment is the same as the implied alignment61 62_Alignas(_Alignof(long long)) long long CompatibleAlignment2; // expected-note {{declared with '_Alignas' attribute here}}63// FIXME: this should be accepted because the redeclaration has no alignment64// specifier.65long long CompatibleAlignment2; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}66 67// FIXME: this should be accepted because the definition specifies the68// alignment and a subsequent declaration does not specify any alignment.69_Alignas(8) long long DefnWithInit = 12; // expected-note {{declared with '_Alignas' attribute here}}70long long DefnWithInit; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}71 72// This is accepted because the definition has an alignment specifier and the73// subsequent redeclaration does not specify an alignment.74_Alignas(8) long long DefnWithInit2 = 12;75extern long long DefnWithInit2;76 77// FIXME: this should be accepted because the definition specifies the78// alignment and a subsequent declaration specifies a compatible alignment.79long long DefnWithInit3 = 12; // expected-error {{'_Alignas' must be specified on definition if it is specified on any declaration}}80_Alignas(_Alignof(long long)) long long DefnWithInit3; // expected-note {{declared with '_Alignas' attribute here}}81 82_Alignas(8) int Mismatch;  // expected-note {{previous declaration is here}}83_Alignas(16) int Mismatch; // expected-error {{redeclaration has different alignment requirement (16 vs 8)}}84