@@ -14,11 +14,23 @@ static int GlobalScopeBadInit3 = takesIntPtr(&ExternGlobal);
1414static int GlobalScopeBadInit4 = 3 * (ExternGlobal + 2 );
1515// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
1616
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+
1725namespace ns {
1826static int NamespaceScope = makesInt();
1927static int NamespaceScopeBadInit = takesInt(ExternGlobal);
2028// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
2129
30+ #if __cplusplus >= 202002L
31+ static int NamespaceScopeConstinit = takesInt(ExternConstinitGlobal);
32+ #endif
33+
2234struct A {
2335 static int ClassScope;
2436 static int ClassScopeBadInit;
@@ -29,6 +41,17 @@ int A::ClassScopeBadInit = takesInt(ExternGlobal);
2941
3042static int FromClassBadInit = takesInt(A::ClassScope);
3143// 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+
3255} // namespace ns
3356
3457// "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;
4265// CHECK-MESSAGES: [[@LINE-1]]:15: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'I'
4366const int B1::I;
4467
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+
4578void f () {
4679 // This is fine, it's executed after dynamic initialization occurs.
4780 static int G = takesInt (ExternGlobal);
@@ -81,4 +114,3 @@ class B2 {
81114};
82115const int B2::I;
83116const int B2::J;
84-
0 commit comments