1 // RUN: %clang_cc1 -std=c++2a -verify %s
4 constinit thread_local
int b
;
5 constinit
static int c
;
8 constinit
static int a
;
9 constinit thread_local
int b
;
10 constinit
int c
; // expected-error {{local variable cannot be declared 'constinit'}}
14 int a
; // expected-note {{add the 'constinit' specifier}}
15 extern constinit
int a
; // expected-error {{added after initialization}}
17 // We allow inheriting 'constinit' from a forward declaration as an extension.
18 extern constinit
int b
; // expected-note {{here}}
19 int b
; // expected-warning {{'constinit' specifier missing}}
23 static constinit
int a
; // expected-note {{here}}
24 static constinit
constexpr int b
; // expected-error {{cannot combine with previous}} expected-note {{here}}
25 static constinit
const int c
= 1;
26 static constinit
const int d
= 1;
28 int S::a
; // expected-warning {{'constinit' specifier missing}}
29 int S::b
; // expected-warning {{'constinit' specifier missing}}
31 inline const int S::d
;
35 static constexpr int b
= 1; // expected-note {{add the 'constinit' specifier}}
36 static const int c
= 1; // expected-note {{add the 'constinit' specifier}}
37 static const int d
= 1; // expected-note {{add the 'constinit' specifier}}
40 constinit
const int T::b
; // expected-error {{'constinit' specifier added after initialization}}
41 constinit
const int T::c
; // expected-error {{'constinit' specifier added after initialization}}
42 constinit
inline const int T::d
; // expected-error {{'constinit' specifier added after initialization}}
44 constinit
void g() {} // expected-error {{constinit can only be used in variable declarations}}
46 // (These used to trigger crashes.)
48 constinit
void h(); // expected-error {{constinit can only be used in variable declarations}}
49 constexpr void i(); // expected-note {{here}}
50 constinit
void i(); // expected-error {{non-constexpr declaration of 'i' follows constexpr declaration}}
51 // expected-error@-1 {{constinit can only be used in variable declarations}}
53 typedef constinit
int type
; // expected-error {{typedef cannot be constinit}}
54 using type
= constinit
int; // expected-error {{type name does not allow constinit specifier}}
55 auto q() -> int constinit
; // expected-error {{type name does not allow constinit specifier}}