Failure to compile std::u16string from libstdc++ 12.1 in c++20 mode · Issue #55560 · llvm/llvm-project (original) (raw)

I'm getting:

error: undefined symbol: void std::__cxx11::basic_string<char16_t, std::char_traits, std::allocator >::_M_construct<char16_t const*>(char16_t const*, char16_t const*, std::forward_iterator_tag)

compiling the following simple test case:

#include #include

// static std::u16string clang_string_workaround(const char16_t* a, const char16_t* b) { return {a, b}; }

std::u16string_view sv{u"test"};

std::u16string print() { return std::u16string(sv); }

int main(int, char**) { std::u16string s = print(); }

on clang 13 and 14.0.0, with clang++ -std=c++20 -o test test.cpp. It works fine with -std=c++17. Bizarrely, it also works if you simply uncomment the clang_string_workaround line which isn't even called. It looks like libstdc++ moved that _M_construct function into a separate file recently, which might be related.