Skip to content

[clang] failure to instantiate template specialization defined after use when used from generic lambda #125747

@zygoloid

Description

Reduced testcase:

template<typename F> constexpr void visit(F f) { f(0); }
template <class T> void G(T t);
int main() { visit([](auto s) -> void { G(s); }); }
template <class T> 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidc++11clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:edgDoes the clang frontend diverge from edg compilerdiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issuerejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions