[clang] failure to instantiate template specialization defined after use when used from generic lambda · Issue #125747 · llvm/llvm-project (original) (raw)
Reduced testcase:
template constexpr void visit(F f) { f(0); } template void G(T t); int main() { visit([](auto s) -> void { G(s); }); } template void G(T t) {}
This should compile and link, but does not, because Clang fails to instantiate G<int>
at the end of the TU. (Accepts-invalid version for testsuite).
Because visit
and the lambda's call operator are constexpr
, they'll get instantiated immediately, which will trigger an attempt to instantiate G<int>
, which will fail because it's not defined yet. But it should then get added to the pending instantiations list to be retried at the end of the translation unit, which appears to not be happening in this case.
Curiously, this bug seems to require a lambda -- if the lambda is replaced by an equivalent struct, the bug disappears. Also, a direct call to the lambda does not trigger the bug; it must be indirectly called via another constexpr function.