Index: clang/lib/Sema/IdentifierResolver.cpp =================================================================== --- clang/lib/Sema/IdentifierResolver.cpp +++ clang/lib/Sema/IdentifierResolver.cpp @@ -121,7 +121,8 @@ // of the controlled statement. // assert(S->getParent() && "No TUScope?"); - if (S->getParent()->getFlags() & Scope::ControlScope) { + if ((S->getParent()->getFlags() & Scope::ControlScope) && + !(S->getFnParent()->getFlags() & Scope::BlockScope)) { S = S->getParent(); if (S->isDeclScope(D)) return true; Index: clang/test/Misc/scope.cpp =================================================================== --- /dev/null +++ clang/test/Misc/scope.cpp @@ -0,0 +1,10 @@ +// RUN: not %clang_cc1 -c -std=c++17 -verify %s +int test() { + if (int foo = [&]() { // expected-error{{redefinition of 'foo'}} + int foo = 0; + return foo; + }(); + foo) { + return 0; + } +} \ No newline at end of file