1 // RUN: %clang_cc1 -ffreestanding -verify=expected,c2x -std=c2x -Wpre-c2x-compat %s 2 // RUN: %clang_cc1 -ffreestanding -verify=expected,c17 -std=c17 %s 3 4 /* WG14 N2934: yes 5 * Revise spelling of keywords v7 6 */ 7 8 thread_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 15 static_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__ <= 201710L 26 #if __alignas_is_defined != 1 27 #error "alignas should be defined" 28 #endif 29 #if __alignof_is_defined != 1 30 #error "alignof should be defined" 31 #endif 32 #else 33 #ifdef __alignas_is_defined 34 #error "alignas should not be defined" 35 #endif 36 #ifdef __alignof_is_defined 37 #error "alignof should not be defined" 38 #endif 39 #endif 40 41 #include <stdbool.h> 42 43 // C17 and earlier must have bool defined as a macro, but C2x and later should 44 // not (at least in Clang's implementation; it's permissible for bool to be a 45 // macro in general, as it could expand to _Bool). 46 #if __STDC_VERSION__ <= 201710L 47 #ifndef bool 48 #error "bool should be defined" 49 #endif 50 #else 51 #ifdef bool 52 #error "bool should not be defined" 53 #endif 54 #endif 55 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 rather 58 // than a specifier. 59 struct 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 in 69 // C++ mode but should be rejected in C. 70 // FIXME: this diagnostic could be improved 71 struct 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 76 struct _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