]> granicus.if.org Git - clang/commitdiff
Static local variables don't result in global constructors being emitted.
authorAnders Carlsson <andersca@mac.com>
Fri, 3 Sep 2010 01:11:38 +0000 (01:11 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 3 Sep 2010 01:11:38 +0000 (01:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112933 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-global-constructors.cpp

index def722b45e463c55b4f4ac94bb02bbf68520f5b7..2a256450887b2e8161fdfa1d9101a31e9aac1d7a 100644 (file)
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
                        compatibilityVersion = "Xcode 2.4";
-                       developmentRegion = English;
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
index 4b116890fa1d475df905f35b94e3670aa11ddb19..9c10b85ad4720d5a8484e6c0c9a72ed011e5a1a3 100644 (file)
@@ -4280,7 +4280,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
   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 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl,
         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);
index a9347ea30018467b5f88242428b8d5dac584cfb7..107bbe129f67b9f6cfa290e8c7cd2d5901e730fb 100644 (file)
@@ -56,3 +56,26 @@ namespace test4 {
   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