Don't consider all local variables in C++ to mandate scope-checking, just

those with initializers.

llvm-svn: 109964
This commit is contained in:
John McCall
2010-08-01 01:24:59 +00:00
parent a95172baa0
commit d4e1b767f3
2 changed files with 22 additions and 2 deletions

View File

@@ -2793,8 +2793,7 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD,
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 @@ 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<Expr>();
@@ -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());

View File

@@ -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;
}
}