Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / dcl.dcl / dcl.spec / dcl.constinit / p1.cpp
blob170c8c7be0c9f423b3f142ecfd7db8151e81920c
1 // RUN: %clang_cc1 -std=c++2a -verify %s
3 constinit int a;
4 constinit thread_local int b;
5 constinit static int c;
7 void f() {
8 constinit static int a;
9 constinit thread_local int b;
10 constinit int c; // expected-error {{local variable cannot be declared 'constinit'}}
13 namespace missing {
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}}
22 struct S {
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}}
30 const int S::c;
31 inline const int S::d;
33 struct T {
34 static int a;
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}}
39 constinit int T::a;
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.)
47 void h();
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}}