https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99209
Bug ID: 99209 Summary: lambdas in function template signatures instantiated with wrong semantic context Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: richard-gccbugzilla at metafoo dot co.uk Target Milestone: --- Testcase: constexpr decltype(auto) f_adl(auto a) { return f(a); } namespace A { constexpr int f(auto) { return 0; } template<int = f_adl([]{})> void g(int = f_adl([]{})) { f_adl([]{}); } } int main() { A::g(); } Here, the f_adl calls for the default template argument and default function argument incorrectly result in errors, because f can't be found by ADL. I suspect this is because the lambdas are being created in the wrong semantic context. (That is also visible in the output of __PRETTY_FUNCTION__ / std::source_location::current().function_name() in the lambda and in the mangling of the lambda closure type, but I think both of those are valid implementation choices -- the function name is implementation-defined and such instantiated lambdas appear to be numbered after those lambdas for which the ABI requires a numbering).