<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60965>60965</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Failure to emit vtable members for std::shared_ptr control block
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ecatmur
      </td>
    </tr>
</table>

<pre>
    Since clang 5 (at least, that's the first version with C++17 support) until current trunk, the following program fails to link:
```c++
#include <functional>
#include <memory>
#include <utility>
template<class> void x() { std::shared_ptr<int>(new int); }
template<class> void y() { x<void>(); }
std::function<void()> a = []()
{
    auto f = [](auto) -> void { y<int>(); };
    auto g = [f](auto k) { return f(k); };
    std::invoke(g, 0);
};
int main() {}
```

With libstdc++ the missing symbols are:
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x10): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x18): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x20): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::_M_dispose()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x28): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::_M_destroy()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-eae5a1.o:(.data.rel.ro._ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE[_ZTVSt15_Sp_counted_ptrIPiLN9__gnu_cxx12_Lock_policyE2EE]+0x30): undefined reference to `std::_Sp_counted_ptr<int*, (__gnu_cxx::_Lock_policy)2>::_M_get_deleter(std::type_info const&)'
```
With libc++ they are:
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x10): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::~__shared_ptr_pointer()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x18): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::~__shared_ptr_pointer()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x20): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::__on_zero_shared()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x28): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::__get_deleter(std::type_info const&) const'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-44ea4b.o:(.data.rel.ro._ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE[_ZTVNSt3__120__shared_ptr_pointerIPiNS_10shared_ptrIiE27__shared_ptr_default_deleteIiiEENS_9allocatorIiEEEE]+0x30): undefined reference to `std::__1::__shared_ptr_pointer<int*, std::__1::shared_ptr<int>::__shared_ptr_default_delete<int, int>, std::__1::allocator<int> >::__on_zero_shared_weak()'
```
Replacing std::shared_ptr with boost::shared_ptr:
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x10): undefined reference to `boost::detail::sp_counted_impl_p<int>::~sp_counted_impl_p()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x18): undefined reference to `boost::detail::sp_counted_impl_p<int>::~sp_counted_impl_p()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x20): undefined reference to `boost::detail::sp_counted_impl_p<int>::dispose()'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x30): undefined reference to `boost::detail::sp_counted_impl_p<int>::get_deleter(std::type_info const&)'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x38): undefined reference to `boost::detail::sp_counted_impl_p<int>::get_local_deleter(std::type_info const&)'
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8bab4b.o:(.data.rel.ro._ZTVN5boost6detail17sp_counted_impl_pIiEE[_ZTVN5boost6detail17sp_counted_impl_pIiEE]+0x40): undefined reference to `boost::detail::sp_counted_impl_p<int>::get_untyped_deleter()'
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl1v4jgX_jXmxgIlTvi64KJQkEaat3q1Xe1Ke2M5yQl4cezIPmlhL-a3r0wI37PTdjTtsItUUbCPn_PxPHGOA8I5OdcAI9Idk-59S1S4MHYEqcCisq3EZOvRo9Qp0FQJPaddSthAIFUgHBI2obgQSFjfUVwAzaV1SJ_AOmk0fZa4oBPCxoSNwz51VVkai4QNaaVRKppW1oJGirbSyxoLaG6UMs9Sz2lpzdyKguZCKkfRUCX1kkR3JLgnwR3pBfVfWjvYjrJI6lRVGVASTfJKpyiNFopE00sGBRTGrr8yWaFUEvezCEWpBAKJJqkSzpFoSp-MzOiKsIHPivTH1GHmQ4zu3EJYyHiJlkQTqdHDsIGGZ-o_sCGJxpT0778BvT6AXpFo4gdrpFOIneMm6cZ6azqlgpLontY8b0frrPvb4lFKqajQ0PzY0o_5INq7sHw468O8DqKJTtHmDVq-h6PLJisLWFlNc8IGy6-g7FKT-sksgbDB3KslqM2bJPZrpEZaCKn3tdtVaaea7cfN6-9ep0omDrOtmDZKLKRzXoduXSRGOSosnKuvEc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