[cfe-commits] r112933 - in /cfe/trunk: clang.xcodeproj/project.pbxproj lib/Sema/SemaDecl.cpp test/SemaCXX/warn-global-constructors.cpp
Anders Carlsson
andersca at mac.com
Thu Sep 2 18:11:38 PDT 2010
Author: andersca
Date: Thu Sep 2 20:11:38 2010
New Revision: 112933
URL: http://llvm.org/viewvc/llvm-project?rev=112933&view=rev
Log:
Static local variables don't result in global constructors being emitted.
Modified:
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-global-constructors.cpp
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=112933&r1=112932&r2=112933&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Thu Sep 2 20:11:38 2010
@@ -2039,7 +2039,6 @@
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
compatibilityVersion = "Xcode 2.4";
- developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=112933&r1=112932&r2=112933&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep 2 20:11:38 2010
@@ -4280,7 +4280,7 @@
if (getLangOptions().CPlusPlus) {
if (!VDecl->isInvalidDecl() &&
!VDecl->getDeclContext()->isDependentContext() &&
- VDecl->hasGlobalStorage() &&
+ VDecl->hasGlobalStorage() && !VDecl->isStaticLocal() &&
!Init->isConstantInitializer(Context,
VDecl->getType()->isReferenceType()))
Diag(VDecl->getLocation(), diag::warn_global_constructor)
@@ -4492,7 +4492,7 @@
Var->setInit(MaybeCreateCXXExprWithTemporaries(Init.takeAs<Expr>()));
if (getLangOptions().CPlusPlus && !Var->isInvalidDecl() &&
- Var->hasGlobalStorage() &&
+ Var->hasGlobalStorage() && !Var->isStaticLocal() &&
!Var->getDeclContext()->isDependentContext() &&
!Var->getInit()->isConstantInitializer(Context, false))
Diag(Var->getLocation(), diag::warn_global_constructor);
Modified: cfe/trunk/test/SemaCXX/warn-global-constructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-global-constructors.cpp?rev=112933&r1=112932&r2=112933&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-global-constructors.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-global-constructors.cpp Thu Sep 2 20:11:38 2010
@@ -56,3 +56,26 @@
char b[5] = "hello";
char c[][5] = { "hello" };
}
+
+namespace test5 {
+ struct A { A(); };
+
+ void f1() {
+ static A a;
+ }
+ void f2() {
+ static A& a = *new A;
+ }
+}
+
+namespace test6 {
+ struct A { ~A(); };
+
+ void f1() {
+ static A a; // expected-warning {{global destructor}}
+ }
+ void f2() {
+ static A& a = *new A;
+ }
+
+}
\ No newline at end of file
More information about the cfe-commits
mailing list