File: n2934.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (79 lines) | stat: -rw-r--r-- 3,250 bytes parent folder | download | duplicates (7)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// RUN: %clang_cc1 -ffreestanding -verify=expected,c2x -std=c2x -Wpre-c2x-compat %s
// RUN: %clang_cc1 -ffreestanding -verify=expected,c17 -std=c17 %s

/* WG14 N2934: yes
 * Revise spelling of keywords v7
 */

thread_local struct S { // c2x-warning {{'thread_local' is incompatible with C standards before C23}} \
                           c2x-error 0+ {{thread-local storage is not supported for the current target}} \
                           c17-error {{unknown type name 'thread_local'}}
  bool b; // c2x-warning {{'bool' is incompatible with C standards before C23}} \
             c17-error {{unknown type name 'bool'}}
} s;

static_assert(alignof(int) != 0, ""); // c2x-warning {{'static_assert' is incompatible with C standards before C23}} \
                                         c2x-warning {{'alignof' is incompatible with C standards before C23}} \
                                         c17-error 2 {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}} \
                                         c17-error {{expected ')'}} \
                                         c17-note {{to match this '('}}

#include <stdalign.h>

// C17 and earlier must have __alignas_is_defined and __alignof_is_defined,
// but C2x and later must not.
#if __STDC_VERSION__ <= 201710L
  #if __alignas_is_defined != 1
    #error "alignas should be defined"
  #endif
  #if __alignof_is_defined != 1
    #error "alignof should be defined"
  #endif
#else
  #ifdef __alignas_is_defined
    #error "alignas should not be defined"
  #endif
  #ifdef __alignof_is_defined
    #error "alignof should not be defined"
  #endif
#endif

#include <stdbool.h>

// C17 and earlier must have bool defined as a macro, but C2x and later should
// not (at least in Clang's implementation; it's permissible for bool to be a
// macro in general, as it could expand to _Bool).
#if __STDC_VERSION__ <= 201710L
  #ifndef bool
    #error "bool should be defined"
  #endif
#else
  #ifdef bool
    #error "bool should not be defined"
  #endif
#endif

// Ensure we correctly parse the alignas keyword in a specifier-qualifier-list.
// This is different than in C++ where alignas is an actual attribute rather
// than a specifier.
struct GH81472 {
  char alignas(8) a1;   // c2x-warning {{'alignas' is incompatible with C standards before C23}}
  alignas(8) char a2;   // c2x-warning {{'alignas' is incompatible with C standards before C23}}
  char _Alignas(8) a3;
  _Alignas(8) char a4;
  char a5 alignas(8);   // expected-error {{expected ';' at end of declaration list}}
  char a6 _Alignas(8);  // expected-error {{expected ';' at end of declaration list}}
};

// Ensure we reject alignas as an attribute specifier. This code is accepted in
// C++ mode but should be rejected in C.
// FIXME: this diagnostic could be improved
struct alignas(8) Reject1 { // expected-error {{declaration of anonymous struct must be a definition}} \
                               expected-warning {{declaration does not declare anything}}
  int a;
};

struct _Alignas(8) Reject2 { // expected-error {{declaration of anonymous struct must be a definition}} \
                                expected-warning {{declaration does not declare anything}}
  int a;
};