]> granicus.if.org Git - clang/commitdiff
Make sure a variable with a C++ direct initializer triggers jump scope checking....
authorEli Friedman <eli.friedman@gmail.com>
Thu, 9 Feb 2012 20:13:14 +0000 (20:13 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 9 Feb 2012 20:13:14 +0000 (20:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150204 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/goto.cpp

index 8ba84fe86a50d8b82e45c2e29850cc41f899c966..ec92470ae1f6d29c8e5cf211e0f624f2aefdcb35 100644 (file)
@@ -16,6 +16,7 @@
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
+#include "clang/Sema/ScopeInfo.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTMutationListener.h"
@@ -9223,6 +9224,9 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl,
     return;
   } 
 
+  if (VDecl->hasLocalStorage())
+    getCurFunction()->setHasBranchProtectedScope();
+
   bool IsDependent = false;
   for (unsigned I = 0, N = Exprs.size(); I != N; ++I) {
     if (DiagnoseUnexpandedParameterPack(Exprs.get()[I], UPPC_Expression)) {
index d8d5ec51f6e40f518cf69b1625f67c6b9d74d8d1..e55e8807239ecf0d10501fabd46ecbf024d1bff5 100644 (file)
@@ -103,3 +103,15 @@ void f() {
  exit:
   return;
 }
+
+namespace PR10620 {
+  struct S {
+    ~S() {}
+  };
+  void g(const S& s) {
+    goto done; // expected-error {{goto into protected scope}}
+    const S s2(s); // expected-note {{jump bypasses variable initialization}}
+  done:
+    ;
+  }
+}