Skip to content

Linker failure in std::make_shared: ~__shared_ptr_emplace / ~_Sp_counted_ptr_inplace #57561

Open
@ecatmur

Description

@ecatmur
#include <memory>
#include <type_traits>
struct G { auto operator()(auto f) { return f(0); } };
int main() {
    auto f = [](auto) -> void { std::make_shared<int>(); };
    static_assert(std::is_invocable_v<G, decltype(f)>);
    f(0);
}

fails linking with undefined reference to (libc++):

(.rodata._ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE]+0x10): undefined reference to `std::__1::__shared_ptr_emplace<int, std::__1::allocator<int> >::~__shared_ptr_emplace()'
(.rodata._ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE]+0x18): undefined reference to `std::__1::__shared_ptr_emplace<int, std::__1::allocator<int> >::~__shared_ptr_emplace()'
(.rodata._ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE]+0x20): undefined reference to `std::__1::__shared_ptr_emplace<int, std::__1::allocator<int> >::__on_zero_shared()'
(.rodata._ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_emplaceIiNS_9allocatorIiEEEE]+0x30): undefined reference to `std::__1::__shared_ptr_emplace<int, std::__1::allocator<int> >::__on_zero_shared_weak()'

or (libstdc++):

(.rodata._ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE]+0x10): undefined reference to `std::_Sp_counted_ptr_inplace<int, std::allocator<int>, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr_inplace()'
(.rodata._ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE]+0x18): undefined reference to `std::_Sp_counted_ptr_inplace<int, std::allocator<int>, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr_inplace()'
(.rodata._ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE]+0x20): undefined reference to `std::_Sp_counted_ptr_inplace<int, std::allocator<int>, (__gnu_cxx::_Lock_policy)2>::_M_dispose()'
(.rodata._ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE]+0x28): undefined reference to `std::_Sp_counted_ptr_inplace<int, std::allocator<int>, (__gnu_cxx::_Lock_policy)2>::_M_destroy()'
(.rodata._ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt23_Sp_counted_ptr_inplaceIiSaIiELN9__gnu_cxx12_Lock_policyE2EE]+0x30): undefined reference to `std::_Sp_counted_ptr_inplace<int, std::allocator<int>, (__gnu_cxx::_Lock_policy)2>::_M_get_deleter(std::type_info const&)'

I guess all the unevaluated-context stuff inside __invokable_r (or libstdc++ equivalent) is persuading Sema that the class template instantiation vtable member emission stuff has already been done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions