brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 55de132 Raw
80 lines · c
1// RUN: %clang_cc1 -ffreestanding -verify=expected,c2x -std=c2x -Wpre-c2x-compat %s2// RUN: %clang_cc1 -ffreestanding -verify=expected,c17 -std=c17 %s3 4/* WG14 N2934: yes5 * Revise spelling of keywords v76 */7 8thread_local struct S { // c2x-warning {{'thread_local' is incompatible with C standards before C23}} \9                           c2x-error 0+ {{thread-local storage is not supported for the current target}} \10                           c17-error {{unknown type name 'thread_local'}}11  bool b; // c2x-warning {{'bool' is incompatible with C standards before C23}} \12             c17-error {{unknown type name 'bool'}}13} s;14 15static_assert(alignof(int) != 0, ""); // c2x-warning {{'static_assert' is incompatible with C standards before C23}} \16                                         c2x-warning {{'alignof' is incompatible with C standards before C23}} \17                                         c17-error 2 {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}} \18                                         c17-error {{expected ')'}} \19                                         c17-note {{to match this '('}}20 21#include <stdalign.h>22 23// C17 and earlier must have __alignas_is_defined and __alignof_is_defined,24// but C2x and later must not.25#if __STDC_VERSION__ <= 201710L26  #if __alignas_is_defined != 127    #error "alignas should be defined"28  #endif29  #if __alignof_is_defined != 130    #error "alignof should be defined"31  #endif32#else33  #ifdef __alignas_is_defined34    #error "alignas should not be defined"35  #endif36  #ifdef __alignof_is_defined37    #error "alignof should not be defined"38  #endif39#endif40 41#include <stdbool.h>42 43// C17 and earlier must have bool defined as a macro, but C2x and later should44// not (at least in Clang's implementation; it's permissible for bool to be a45// macro in general, as it could expand to _Bool).46#if __STDC_VERSION__ <= 201710L47  #ifndef bool48    #error "bool should be defined"49  #endif50#else51  #ifdef bool52    #error "bool should not be defined"53  #endif54#endif55 56// Ensure we correctly parse the alignas keyword in a specifier-qualifier-list.57// This is different than in C++ where alignas is an actual attribute rather58// than a specifier.59struct GH81472 {60  char alignas(8) a1;   // c2x-warning {{'alignas' is incompatible with C standards before C23}}61  alignas(8) char a2;   // c2x-warning {{'alignas' is incompatible with C standards before C23}}62  char _Alignas(8) a3;63  _Alignas(8) char a4;64  char a5 alignas(8);   // expected-error {{expected ';' at end of declaration list}}65  char a6 _Alignas(8);  // expected-error {{expected ';' at end of declaration list}}66};67 68// Ensure we reject alignas as an attribute specifier. This code is accepted in69// C++ mode but should be rejected in C.70// FIXME: this diagnostic could be improved71struct alignas(8) Reject1 { // expected-error {{declaration of anonymous struct must be a definition}} \72                               expected-warning {{declaration does not declare anything}}73  int a;74};75 76struct _Alignas(8) Reject2 { // expected-error {{declaration of anonymous struct must be a definition}} \77                                expected-warning {{declaration does not declare anything}}78  int a;79};80