A lambda in a function template may be recursively instantiated as the following example:
template <unsigned v> struct Number { static constexpr unsigned value = v; }; template <unsigned IBegin = 0, unsigned IEnd = 1> constexpr auto fun1(Number<IBegin> = Number<0>{}, Number<IEnd> = Number<1>{}) { auto f = [&](auto fs, auto i) { if constexpr(i.value > 0) { return fs(fs, Number<IBegin>{}); } }; return f(f, Number<IEnd>{}); } void fun2() { fun1(); }
The recursive lambda will cause a lambda function instantiated twice, one inside another.
The inner LocalInstantiationScope should not be marked as MergeWithParentScope
since it already has references to locals properly substituted, otherwise it causes
assertion due to the check for duplicate locals in merged LocalInstantiationScope.