aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 021673bf07..d8d77b0d54 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1325,8 +1325,12 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
} else if (!VDecl->isInvalidDecl()) {
if (CheckInitializerTypes(Init, DclT))
VDecl->setInvalidDecl();
- if (SC == VarDecl::Static) // C99 6.7.8p4.
- CheckForConstantInitializer(Init, DclT);
+
+ // C++ 3.6.2p2, allow dynamic initialization of static initializers.
+ if (!getLangOptions().CPlusPlus) {
+ if (SC == VarDecl::Static) // C99 6.7.8p4.
+ CheckForConstantInitializer(Init, DclT);
+ }
}
} else if (VDecl->isFileVarDecl()) {
if (VDecl->getStorageClass() == VarDecl::Extern)
@@ -1335,8 +1339,11 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
if (CheckInitializerTypes(Init, DclT))
VDecl->setInvalidDecl();
- // C99 6.7.8p4. All file scoped initializers need to be constant.
- CheckForConstantInitializer(Init, DclT);
+ // C++ 3.6.2p2, allow dynamic initialization of static initializers.
+ if (!getLangOptions().CPlusPlus) {
+ // C99 6.7.8p4. All file scoped initializers need to be constant.
+ CheckForConstantInitializer(Init, DclT);
+ }
}
// If the type changed, it means we had an incomplete type that was
// completed by the initializer. For example: