aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-08-22 05:00:02 +0000
committerAnders Carlsson <andersca@mac.com>2008-08-22 05:00:02 +0000
commitc5eb7311445bb14b6a26eb2ad667fe7a1ca20887 (patch)
tree3890b88f1e9672c53497c84798f21b93651ed103 /lib/Sema/SemaDecl.cpp
parent91e45d1c6cb59dca7598192fcc78b3793aaba22f (diff)
Initial sema support for C++ static initializers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55166 91177308-0d34-0410-b5e6-96231b3b80d8
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: