[Clang] Linker error: missing std::_Sp_counted_ptr_inplace<P<int>::D, ...> members
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
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::D, ...>` but does not emit the corresponding definitions.
## Reproducer
```cpp
#include
#include
template struct P{ P(T): p(std::make_shared()){} struct D{}; std::shared_ptr p; };
template struct W{ F f; auto operator()(...) { return f(0,0); } };
int main(){ std::function{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::D, std::allocator, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr_inplace()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace::D, std::allocator, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr_inplace()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace::D, std::allocator, (__gnu_cxx::_Lock_policy)2>::_M_dispose()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace::D, std::allocator, (__gnu_cxx::_Lock_policy)2>::_M_destroy()'
/usr/bin/ld: ... undefined reference to `std::_Sp_counted_ptr_inplace::D, std::allocator, (__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.
Contributor guide
Research direction
Start with the standalone C++23 reproducer and run the listed clang++-21/22 and g++ commands using the stated libstdc++ setup. Compare the generated object symbols and linker diagnostics to locate why the std::_Sp_counted_ptr_inplace members are missing. The payload names no LLVM source file or test; done means the reproducer links successfully with Clang and the failure has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100