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

    <tr>
        <th>Summary</th>
        <td>
            [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>
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          ashley-hawkins
      </td>
    </tr>
</table>

<pre>
    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)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VkuP47gR_jXsS6EFiXoffOjHGPBhgABBEOxpQZFli9MU6SWptr2H_PagKLnbM92ZzSbAAob8qudXVV-VCEEfLOKG1Y-sfr4Tcxyd34gwGrzcj-L0om24G5y6bP7uvL-A3kMcEaKOBkEHsC7CK_oLSIPCZ_AogpbCmCSpLUwXmIS2mZSwY7ydQE9H56O2BxAwOTUbZPwJhFUQRxHXnwDPJBVAwH62Mmpn4TRqOYLHOHsbIETFygdWPoTotT1cbeyAnC-m3jT33k3XKEhQRzhpY2AvtIHoQLrpqA2Cs2BExBBBGmEPcNJxBAFG2xf0gN47nyyz_JnlD6zJ19fylW_dMTK-Xa35ezwfjfPoGd8epLwPVhzD6EjE6GH5kfHtuWt-bap7o-18vj_YmfFtUWV5VjC-zbKPj0_kB23JKAECT1_FC261wcD41uPRu0xpCmHNP3Mkpe07OqzJ38AUxjgpovO_Ri90DKx8-vgfK5_kKDwrvwArvyx_Klz_Rsa7n6kw3lAJ0jf-QB9nm1pQgXFUx57xlrT_UlC1lWZWSI4Yf0yvd4WBgODblMyKSzay8qEuSsJytgr3mhLwuEePViI11aew3uDwEbY_wCQBkhpzDbF8WHqSPqw9Kt000RhQZ6NaGhjPOoJ0CqEAxrs5INy_UoQBEbR9JffaWfLyaV-n5w6i16hIbRIvSLOrrZ6EgdRjapboYZjjOuTECmH2CKcR44genE-_xVEHYg0h45xIYrVCOQ8oBQW3A0XRtBFerDslGqH4Z6NgwHd3S3ZujvARZnKX9BhvA4QjSr1fWUnA0bvB4LSA81E3g51dWYhI6-J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