@@ -14,11 +14,23 @@ static int GlobalScopeBadInit3 = takesIntPtr(&ExternGlobal);
14
14
static int GlobalScopeBadInit4 = 3 * (ExternGlobal + 2 );
15
15
// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
16
16
17
+ #if __cplusplus >= 202002L
18
+ extern constinit int ExternConstinitGlobal;
19
+ static int GlobalScopeConstinit1 = ExternConstinitGlobal;
20
+ static int GlobalScopeConstinit2 = takesInt(ExternConstinitGlobal);
21
+ static int GlobalScopeConstinit3 = takesIntPtr(&ExternConstinitGlobal);
22
+ static int GlobalScopeConstinit4 = 3 * (ExternConstinitGlobal + 2 );
23
+ #endif
24
+
17
25
namespace ns {
18
26
static int NamespaceScope = makesInt();
19
27
static int NamespaceScopeBadInit = takesInt(ExternGlobal);
20
28
// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
21
29
30
+ #if __cplusplus >= 202002L
31
+ static int NamespaceScopeConstinit = takesInt(ExternConstinitGlobal);
32
+ #endif
33
+
22
34
struct A {
23
35
static int ClassScope;
24
36
static int ClassScopeBadInit;
@@ -29,6 +41,17 @@ int A::ClassScopeBadInit = takesInt(ExternGlobal);
29
41
30
42
static int FromClassBadInit = takesInt(A::ClassScope);
31
43
// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ClassScope'
44
+
45
+ #if __cplusplus >= 202002L
46
+ struct B {
47
+ static constinit int ClassScopeConstinit;
48
+ static int ClassScopeFromConstinit;
49
+ };
50
+
51
+ int B::ClassScopeFromConstinit = takesInt(ExternConstinitGlobal);
52
+ static int FromClassScopeConstinit = takesInt(B::ClassScopeConstinit);
53
+ #endif
54
+
32
55
} // namespace ns
33
56
34
57
// "const int B::I;" is fine, it just ODR-defines B::I. See [9.4.3] Static
@@ -42,6 +65,16 @@ const int B1::J;
42
65
// CHECK-MESSAGES: [[@LINE-1]]:15: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'I'
43
66
const int B1::I;
44
67
68
+ #if __cplusplus >= 202002L
69
+ class D {
70
+ static const constinit int I = 0 ;
71
+ static const int J = I;
72
+ };
73
+
74
+ const int D::J;
75
+ const int D::I;
76
+ #endif
77
+
45
78
void f () {
46
79
// This is fine, it's executed after dynamic initialization occurs.
47
80
static int G = takesInt (ExternGlobal);
@@ -81,4 +114,3 @@ class B2 {
81
114
};
82
115
const int B2::I;
83
116
const int B2::J;
84
-
0 commit comments