SFML: Can't compile `sf::String` with Libc++ 18 due to undefined `std::char_traits`
Can’t compile sf::String with Libc++ 18 due to undefined std::char_traits<std::uint8_t>
The C++ standard library doesn’t define std::char_traits<std::uint8_t>.
It used to compile fine with https://github.com/llvm/llvm-project/tree/c0abd3814564a568dfc607c216e6407eaa314f46.
Your environment
- OS: Arch Linux.
- SFML version:
master. - Clang 18 (https://github.com/llvm/llvm-project/tree/985e399647d591d6130ba6fe08c5b5f6cb87d9f6).
- Special compiler flags used:
-stdlib=libc++.
Steps to reproduce
cmake -S SFML -B build -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS=-stdlib=libc++
cmake --build build/
Expected behavior
To build just fine.
Actual behavior
This error happens:
In module 'std_string' imported from /home/johel/Documents/C++/Forks/SFML/SFML/include/SFML/System/String.hpp:35:
/home/johel/root/clang-main/bin/../include/c++/v1/string:723:46: error: implicit instantiation of undefined template 'std::char_traits<unsigned char>'
723 | static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
| ^
/home/johel/Documents/C++/Forks/SFML/SFML/src/SFML/System/String.cpp:171:41: note: in instantiation of template class 'std::basic_string<unsigned char>' requested here
171 | std::basic_string<std::uint8_t> String::toUtf8() const
| ^
/home/johel/root/clang-main/bin/../include/c++/v1/__fwd/string.h:23:29: note: template is declared here
23 | struct _LIBCPP_TEMPLATE_VIS char_traits;
| ^
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 22 (18 by maintainers)
FWIW even if we temporarily revert the change, that specialization is deprecated and you folks should find a way to move off of it.
std::basic_string<uint8_t>is not strictly eStandard C++, that’s the bottom line.Instead of changing
basic_string<uint8_t>to plainstringand thus losing the typesystem distinction you worked hard to create in the first place, I would suggest something more like this: https://github.com/Quuxplusone/SFML/commit/alternative-llvm18-string-fix The idea here is simply to define your ownsf::char_traits_uint8_tto replace the disappearedstd::char_traits<uint8_t>, and then usebasic_string<uint8_t, sf::char_traits_uint8_t>everywhere you previously usedbasic_string<uint8_t>. (I gave it a typedef aliassf::U8Stringas well; that’s orthogonal to the main idea of the patch, but IMHO the alias is a good idea no matter whether you like the main idea or not.)IMO the best best outcome would be if you can persuade @philnik777 to revert the libc++18 change that caused this churn… but I don’t claim that that direction is likely to succeed. The question is just how many C++ projects libc++18 is willing to break to make this omelet; I think the answer is probably “lots more than just SFML.”
Probably https://github.com/llvm/llvm-project/commit/e30a148b098d462d0267c479cd9e4783363c2761
Now it warns: