@@ -1325,8 +1325,12 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
1325
1325
} else if (!VDecl->isInvalidDecl ()) {
1326
1326
if (CheckInitializerTypes (Init, DclT))
1327
1327
VDecl->setInvalidDecl ();
1328
- if (SC == VarDecl::Static) // C99 6.7.8p4.
1329
- CheckForConstantInitializer (Init, DclT);
1328
+
1329
+ // C++ 3.6.2p2, allow dynamic initialization of static initializers.
1330
+ if (!getLangOptions ().CPlusPlus ) {
1331
+ if (SC == VarDecl::Static) // C99 6.7.8p4.
1332
+ CheckForConstantInitializer (Init, DclT);
1333
+ }
1330
1334
}
1331
1335
} else if (VDecl->isFileVarDecl ()) {
1332
1336
if (VDecl->getStorageClass () == VarDecl::Extern)
@@ -1335,8 +1339,11 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
1335
1339
if (CheckInitializerTypes (Init, DclT))
1336
1340
VDecl->setInvalidDecl ();
1337
1341
1338
- // C99 6.7.8p4. All file scoped initializers need to be constant.
1339
- CheckForConstantInitializer (Init, DclT);
1342
+ // C++ 3.6.2p2, allow dynamic initialization of static initializers.
1343
+ if (!getLangOptions ().CPlusPlus ) {
1344
+ // C99 6.7.8p4. All file scoped initializers need to be constant.
1345
+ CheckForConstantInitializer (Init, DclT);
1346
+ }
1340
1347
}
1341
1348
// If the type changed, it means we had an incomplete type that was
1342
1349
// completed by the initializer. For example:
0 commit comments