]> granicus.if.org Git - clang/commitdiff
Commit some missing changes to the previous patch.
authorSean Hunt <scshunt@csclub.uwaterloo.ca>
Wed, 11 May 2011 22:50:12 +0000 (22:50 +0000)
committerSean Hunt <scshunt@csclub.uwaterloo.ca>
Wed, 11 May 2011 22:50:12 +0000 (22:50 +0000)
This means we get C++0x jump-across-intializer semantics correct.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131204 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp

index 44e47ea8d86c7272cf3b90928b31daea26096ef0..6fafdbed69ebd5acd4bbf112201c9e704bb03848 100644 (file)
@@ -5657,13 +5657,25 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl,
       //   program is ill-formed.
       // C++0x [dcl.init]p11:
       //   If no initializer is specified for an object, the object is
-      //   default-intiialized; [...].
+      //   default-intialized; [...].
     } 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())
-        getCurFunction()->setHasBranchProtectedScope();
+      // C++0x [stmt.dcl]p3
+      //   A program that jumps from a point where a variable with automatic
+      //   storage duration is not ins cope to a point where it is in scope is
+      //   ill-formed unless the variable has scalar type, class type with a
+      //   trivial defautl constructor and a trivial destructor, a cv-qualified
+      //   version of one of these types, or an array of one of the preceding
+      //   types and is declared without an initializer.
+      if (getLangOptions().CPlusPlus && Var->hasLocalStorage() && Record) {
+        CXXRecordDecl *CXXRecord = cast<CXXRecordDecl>(Record->getDecl());
+        if (!getLangOptions().CPlusPlus0x ||
+            !CXXRecord->hasTrivialDefaultConstructor() ||
+            !CXXRecord->hasTrivialDestructor())
+          getCurFunction()->setHasBranchProtectedScope();
+      }
 
       InitializedEntity Entity = InitializedEntity::InitializeVariable(Var);
       InitializationKind Kind
index bd16cda9f12c92a26bf7662ff7e21887b97a7597..b00d73d93c8ed724d7843b35ebbb7ed1e92e414d 100644 (file)
@@ -3210,7 +3210,7 @@ bool Sema::ShouldDeleteDefaultConstructor(CXXConstructorDecl *CD) {
           return true;
 
         // Don't try to initialize the anonymous union
-        // This is technically non-conformant, but sanity deamands it.
+        // This is technically non-conformant, but sanity demands it.
         continue;
       }
     }