Issue 86893
Summary [C++20] [Modules] Undefined reference to std::allocator<char>::deallocate in Clang trunk when a function exported from a module returns a type template instantiation which uses std::allocator<char>
Labels clang
Assignees
Reporter ashley-hawkins
    Sorry if the title is not very clear. Basically if in my main.cc I'm importing a module, and that module exports a function which returns std::string, and I call that function from main.cc, it will fail to compile on latest clang with a linker error that
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/../../../../x86_64-linux-gnu/bin/ld: CMakeFiles/repro.dir/main.cc.o: in function `std::allocator_traits<std::allocator<char> >::deallocate(std::allocator<char>&, char*, unsigned long)':
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/../../../../include/c++/14.0.1/bits/alloc_traits.h:513: undefined reference to `std::allocator<char>::deallocate(char*, unsigned long)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```

I tried to make a minimal reproducer but I'm not sure whether or not this is actually minimal, because I don't know if it could be reproduced without std::allocator or if it's specifically a problem with std::allocator. In module.cc you can change the return type of repro::repro to `std::string` to see that it also happens with `std::string`. It also happens with `std::vector<char>`, and `std::deque<char>`, and I guess any other standard container would have the same problem with an element type of char. I wasn't able to reproduce without using modules, which is why I labelled it as a modules problem.

Compiler Explorer reproducer for 19.0.0git: https://godbolt.org/z/8vYqYj9ro
Compiler Explorer example of inability to reproduce for 18.1.0: https://godbolt.org/z/8s6x9nzMx (same code as in above I just changed the compiler to x86-64 Clang 18.1.0)

As of writing this:

Problematic version of Clang tested on Compiler Explorer:
> clang version 19.0.0git (https://github.com/llvm/llvm-project.git c43932ebdc407ed9633f7468dcb061b635e99a8d)

Problematic version of Clang that I originally found the problem on, from apt.llvm.org:
> Debian clang version 19.0.0 (++20240327112225+c9d12664f2f9-1\~exp1\~20240327112239.613) c9d12664f2f9

Working version of Clang tested on Compiler Explorer:
> clang version 18.1.0rc (https://github.com/llvm/llvm-project.git 461274b81d8641eab64d494accddc81d7db8a09e)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to