Issue 185011
Summary [Clang] Linker error: missing std::_Sp_counted_ptr_inplace<P<int>::D, ...> members
Labels clang
Assignees
Reporter craffael
    I can reproduce a linker failure with Clang on a very small self-contained C++23 source. The same source links successfully with GCC on the same machine.

This looks like Clang emits references to the virtual members of `std::_Sp_counted_ptr_inplace<P<int>::D, ...>` but does not emit the corresponding definitions.

## Reproducer

```cpp
#include <functional>
#include <memory>
template<class T> struct P{ P(T): p(std::make_shared<D>()){} struct D{}; std::shared_ptr<D> p; };
template<class F> struct W{ F f; auto operator()(...) { return f(0,0); } };
int main(){ std::function<int(int,int)>{W{[](int, auto)->int{ return P(0),0; }}}; }
```

## Commands

Fails:

```bash
clang++-21 -std=c++23 repro.cc -o repro
clang++-22 -std=c++23 repro.cc -o repro
```

Succeeds:

```bash
g++ -std=c++23 repro.cc -o repro
```

## Actual result

`clang++-21` and `clang++-22` both fail at link time with:

```text
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace<P<int>::D, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr_inplace()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace<P<int>::D, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr_inplace()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace<P<int>::D, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace<P<int>::D, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_destroy()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace<P<int>::D, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_get_deleter(std::type_info const&)'
clang++-21: error: linker command failed with exit code 1
```

## Expected result

The program should link successfully, as it does with GCC on the same system.

## Environment

- Tested on March 6, 2026
- `clang++-21`: `Ubuntu clang version 21.1.8 (++20251221032922+2078da43e25a-1~exp1~20251221153059.70)`
- `clang++-22`: `Ubuntu clang version 22.1.1 (++20260228104553+108df0694cc1-1~exp1~20260228104610.34)`
- `g++`: `g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0`
- `clang++-21 -v` selects GCC installation `/usr/local/gcc-15/lib/gcc/x86_64-pc-linux-gnu/15.2.1`
- The libstdc++ headers used by Clang come from `/usr/local/gcc-15/.../include/c++/15.2.1`
- Target: `x86_64-pc-linux-gnu`
- Linker in the default repro command: `/usr/bin/ld`

## Notes

- The reproducer came out of a larger real-world codebase, but the source above is standalone.
- I also reduced this to a no-`#include` preprocessed `.ii` file and reduced it further with creduce. But the result was still 700kB in size and was very hard to read. I can attach the `.ii` reduction too if that is useful.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to