[cfe-commits] r109964 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/scope-check.cpp

John McCall rjmccall at apple.com
Sat Jul 31 18:25:00 PDT 2010


Author: rjmccall
Date: Sat Jul 31 20:24:59 2010
New Revision: 109964

URL: http://llvm.org/viewvc/llvm-project?rev=109964&view=rev
Log:
Don't consider all local variables in C++ to mandate scope-checking, just
those with initializers.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/scope-check.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=109964&r1=109963&r2=109964&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Jul 31 20:24:59 2010
@@ -2793,8 +2793,7 @@
 
   bool isVM = T->isVariablyModifiedType();
   if (isVM || NewVD->hasAttr<CleanupAttr>() ||
-      NewVD->hasAttr<BlocksAttr>() ||
-      (LangOpts.CPlusPlus && NewVD->hasLocalStorage()))
+      NewVD->hasAttr<BlocksAttr>())
     setFunctionHasBranchProtectedScope();
 
   if ((isVM && NewVD->hasLinkage()) ||
@@ -3934,6 +3933,9 @@
     return;
   }
 
+  if (getLangOptions().CPlusPlus && VDecl->hasLocalStorage())
+    setFunctionHasBranchProtectedScope();
+
   // Take ownership of the expression, now that we're sure we have somewhere
   // to put it.
   Expr *Init = init.takeAs<Expr>();
@@ -4253,6 +4255,12 @@
       //   program is ill-formed.
       // FIXME: DPG thinks it is very fishy that C++0x disables this.
     } else {
+      // Check for jumps past the implicit initializer.  C++0x
+      // clarifies that this applies to a "variable with automatic
+      // storage duration", not a "local variable".
+      if (getLangOptions().CPlusPlus && Var->hasLocalStorage())
+        setFunctionHasBranchProtectedScope();
+
       InitializedEntity Entity = InitializedEntity::InitializeVariable(Var);
       InitializationKind Kind
         = InitializationKind::CreateDefault(Var->getLocation());

Modified: cfe/trunk/test/SemaCXX/scope-check.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/scope-check.cpp?rev=109964&r1=109963&r2=109964&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/scope-check.cpp (original)
+++ cfe/trunk/test/SemaCXX/scope-check.cpp Sat Jul 31 20:24:59 2010
@@ -121,3 +121,15 @@
   }
 }
 
+// C++0x says it's okay to skip non-trivial initializers on static
+// locals, and we implement that in '03 as well.
+namespace test7 {
+  struct C { C(); };
+
+  void test() {
+    goto foo;
+    static C c;
+  foo:
+    return;
+  }
+}





More information about the cfe-commits mailing list