Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -6999,6 +6999,21 @@ return; } } + + if (cast(ShadowedDecl)->hasLocalStorage()) { + // A variable can't shadow a local variable in an enclosing scope, if + // they are separated by a non-capturing declaration context. + for (DeclContext *ParentDC = NewDC; + ParentDC && !ParentDC->Equals(OldDC); + ParentDC = getLambdaAwareParentOfDeclContext(ParentDC)) { + // Only block literals, captured statements, and lambda expressions + // can capture; other scopes don't. + if (!isa(ParentDC) && !isa(ParentDC) && + !isLambdaCallOperator(ParentDC)) { + return; + } + } + } } } Index: test/SemaCXX/warn-shadow.cpp =================================================================== --- test/SemaCXX/warn-shadow.cpp +++ test/SemaCXX/warn-shadow.cpp @@ -213,3 +213,12 @@ void handleLinkageSpec() { typedef void externC; // expected-warning {{declaration shadows a typedef in the global namespace}} } + +namespace PR33947 { +void f(int a) { + struct A { + void g(int a) {} + A() { int a; } + }; +} +}