diff --git a/clang/lib/Sema/IdentifierResolver.cpp b/clang/lib/Sema/IdentifierResolver.cpp --- a/clang/lib/Sema/IdentifierResolver.cpp +++ b/clang/lib/Sema/IdentifierResolver.cpp @@ -121,7 +121,10 @@ // of the controlled statement. // assert(S->getParent() && "No TUScope?"); - if (S->getParent()->getFlags() & Scope::ControlScope) { + // If the current decl is in a lambda, we shouldn't consider this is a + // redefinition as lambda has its own scope. + if (S->getParent()->getFlags() & Scope::ControlScope && + !S->isFunctionScope()) { S = S->getParent(); if (S->isDeclScope(D)) return true; diff --git a/clang/test/SemaCXX/cxx1z-init-statement.cpp b/clang/test/SemaCXX/cxx1z-init-statement.cpp --- a/clang/test/SemaCXX/cxx1z-init-statement.cpp +++ b/clang/test/SemaCXX/cxx1z-init-statement.cpp @@ -90,3 +90,18 @@ static_assert(constexpr_switch_init(-2) == 0, ""); static_assert(constexpr_switch_init(-5) == -1, ""); } + +int test_lambda_init() { + if (int x = []() {int x = 42; return x; }(); x) { + }; + + switch (int y = []() {int y = 42; return y; }(); y) { + case 42: + return 1; + } + + for (int x = [] { int x = 0; return x; }();;) + ; + + return 0; +}