Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -3621,15 +3621,6 @@ D = getCanonicalParmVarDecl(D); llvm::PointerUnion &Stored = LocalDecls[D]; if (Stored.isNull()) { -#ifndef NDEBUG - // It should not be present in any surrounding scope either. - LocalInstantiationScope *Current = this; - while (Current->CombineWithOuterScope && Current->Outer) { - Current = Current->Outer; - assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() && - "Instantiated local in inner and outer scopes"); - } -#endif Stored = Inst; } else if (DeclArgumentPack *Pack = Stored.dyn_cast()) { Pack->push_back(cast(Inst)); @@ -3646,14 +3637,6 @@ } void LocalInstantiationScope::MakeInstantiatedLocalArgPack(const Decl *D) { -#ifndef NDEBUG - // This should be the first time we've been told about this decl. - for (LocalInstantiationScope *Current = this; - Current && Current->CombineWithOuterScope; Current = Current->Outer) - assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() && - "Creating local pack after instantiation of local"); -#endif - D = getCanonicalParmVarDecl(D); llvm::PointerUnion &Stored = LocalDecls[D]; DeclArgumentPack *Pack = new DeclArgumentPack; Index: clang/test/SemaCXX/recursive-lambda.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/recursive-lambda.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s + +// expected-no-diagnostics + +// Check recursive instantiation of lambda does not cause assertion. + +template +struct Number +{ + static constexpr unsigned value = v; +}; + +template +constexpr auto fun1(Number = Number<0>{}, Number = Number<1>{}) +{ + auto f = [&](auto fs, auto i) { + if constexpr(i.value > 0) + { + return fs(fs, Number{}); + } + }; + + return f(f, Number{}); +} + + +void fun2() { + fun1(); +}