Skip to content

Commit d4e1b76

Browse files
committed
Don't consider all local variables in C++ to mandate scope-checking, just
those with initializers. llvm-svn: 109964
1 parent a95172b commit d4e1b76

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,8 +2793,7 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD,
27932793

27942794
bool isVM = T->isVariablyModifiedType();
27952795
if (isVM || NewVD->hasAttr<CleanupAttr>() ||
2796-
NewVD->hasAttr<BlocksAttr>() ||
2797-
(LangOpts.CPlusPlus && NewVD->hasLocalStorage()))
2796+
NewVD->hasAttr<BlocksAttr>())
27982797
setFunctionHasBranchProtectedScope();
27992798

28002799
if ((isVM && NewVD->hasLinkage()) ||
@@ -3934,6 +3933,9 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) {
39343933
return;
39353934
}
39363935

3936+
if (getLangOptions().CPlusPlus && VDecl->hasLocalStorage())
3937+
setFunctionHasBranchProtectedScope();
3938+
39373939
// Take ownership of the expression, now that we're sure we have somewhere
39383940
// to put it.
39393941
Expr *Init = init.takeAs<Expr>();
@@ -4253,6 +4255,12 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl,
42534255
// program is ill-formed.
42544256
// FIXME: DPG thinks it is very fishy that C++0x disables this.
42554257
} else {
4258+
// Check for jumps past the implicit initializer. C++0x
4259+
// clarifies that this applies to a "variable with automatic
4260+
// storage duration", not a "local variable".
4261+
if (getLangOptions().CPlusPlus && Var->hasLocalStorage())
4262+
setFunctionHasBranchProtectedScope();
4263+
42564264
InitializedEntity Entity = InitializedEntity::InitializeVariable(Var);
42574265
InitializationKind Kind
42584266
= InitializationKind::CreateDefault(Var->getLocation());

clang/test/SemaCXX/scope-check.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,15 @@ namespace test6 {
121121
}
122122
}
123123

124+
// C++0x says it's okay to skip non-trivial initializers on static
125+
// locals, and we implement that in '03 as well.
126+
namespace test7 {
127+
struct C { C(); };
128+
129+
void test() {
130+
goto foo;
131+
static C c;
132+
foo:
133+
return;
134+
}
135+
}

0 commit comments

Comments
 (0)