[cfe-commits] r55166 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/static-initializers.cpp
Anders Carlsson
andersca at mac.com
Thu Aug 21 22:00:02 PDT 2008
Author: andersca
Date: Fri Aug 22 00:00:02 2008
New Revision: 55166
URL: http://llvm.org/viewvc/llvm-project?rev=55166&view=rev
Log:
Initial sema support for C++ static initializers.
Added:
cfe/trunk/test/SemaCXX/static-initializers.cpp
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=55166&r1=55165&r2=55166&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Aug 22 00:00:02 2008
@@ -1325,8 +1325,12 @@
} 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 @@
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:
Added: cfe/trunk/test/SemaCXX/static-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/static-initializers.cpp?rev=55166&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/static-initializers.cpp (added)
+++ cfe/trunk/test/SemaCXX/static-initializers.cpp Fri Aug 22 00:00:02 2008
@@ -0,0 +1,12 @@
+// RUN: clang -fsyntax-only -verify %s
+int f()
+{
+ return 10;
+}
+
+void g()
+{
+ static int a = f();
+}
+
+static int b = f();
More information about the cfe-commits
mailing list