From e46f62cbaaa6294d84be09f3c9b910a2031be913 Mon Sep 17 00:00:00 2001 From: John McCall Date: Sun, 1 Aug 2010 01:24:59 +0000 Subject: [PATCH] Don't consider all local variables in C++ to mandate scope-checking, just those with initializers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109964 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 12 ++++++++++-- test/SemaCXX/scope-check.cpp | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a6ba359972..b1018bff49 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2793,8 +2793,7 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, bool isVM = T->isVariablyModifiedType(); if (isVM || NewVD->hasAttr() || - NewVD->hasAttr() || - (LangOpts.CPlusPlus && NewVD->hasLocalStorage())) + NewVD->hasAttr()) setFunctionHasBranchProtectedScope(); if ((isVM && NewVD->hasLinkage()) || @@ -3934,6 +3933,9 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { 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(); @@ -4253,6 +4255,12 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, // 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()); diff --git a/test/SemaCXX/scope-check.cpp b/test/SemaCXX/scope-check.cpp index cef64f6322..dd70d9744a 100644 --- a/test/SemaCXX/scope-check.cpp +++ b/test/SemaCXX/scope-check.cpp @@ -121,3 +121,15 @@ namespace test6 { } } +// 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; + } +} -- 2.50.1