Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Fails to build on recent libc++ (20 tested) #1812

Description

@benine203

I tracked down this source file Release/include/cpprest/streams.h

template<>
struct Value2StringFormatter<uint8_t>
{
    template<typename T>
    static std::basic_string<uint8_t> format(const T& val)
    {
        std::basic_ostringstream<char> ss;
        ss << val;
        return reinterpret_cast<const uint8_t*>(ss.str().c_str());
    }

    static std::basic_string<uint8_t> format(const utf16string& val)
    {
        return format(utility::conversions::utf16_to_utf8(val));
    }
};

Here it assumes that the standard lib will accomodate instantiating a std::basic_string<uint8_t> or any other T for that matter, but that isn't the case as only the 'regular' char types are specialized for char_traits in the standard.

Current libstdc++ and older libc++ (up to at least libc++18) will accept this code, but not in recent libc++ where only the stipulated types are supported.

This can be isolated further with the following snippet:

Snippet:

// tst.cc
#include <cstdint>
#include <string>

int main() {
  auto s1 = std::basic_string<char>{};
  auto s2 = std::basic_string<uint8_t>{};
}

msvc: OK
gcc: OK
clang+libstdc++: OK
clang+old-libc++: OK
clang+libc++-20: FAIL

$ dpkg -l | egrep 'libc\+\+-[[:digit:]]{2}-dev'
ii  libc++-20-dev:amd64                           1:20~++20241203111125+9a4c5a59d4ec-1~exp1~20241203111142.2504 amd64        LLVM C++ Standard library (development files)

$ clang++ -v -stdlib=libc++  tst.cc
Debian clang version 20.0.0 (++20241203111125+9a4c5a59d4ec-1~exp1~20241203111142.2504)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-20/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/lib/llvm-20/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name tst.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/deb -v -fcoverage-compilation-dir=/home/deb -resource-dir /usr/lib/llvm-20/lib/clang/20 -internal-isystem /usr/lib/llvm-20/bin/../include/c++/v1 -internal-isystem /usr/lib/llvm-20/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/tst-398935.o -x c++ tst.cc
clang -cc1 version 20.0.0 based upon LLVM 20.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/llvm-20/bin/../include/c++/v1
 /usr/lib/llvm-20/lib/clang/20/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
In file included from tst.cc:2:
/usr/lib/llvm-20/bin/../include/c++/v1/string:831:42: error: implicit instantiation of undefined template 'std::char_traits<unsigned char>'
  831 |   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
      |                                          ^
tst.cc:6:13: note: in instantiation of template class 'std::basic_string<unsigned char>' requested here
    6 |   auto s2 = std::basic_string<uint8_t>{};
      |             ^
/usr/lib/llvm-20/bin/../include/c++/v1/__fwd/string.h:23:29: note: template is declared here
   23 | struct _LIBCPP_TEMPLATE_VIS char_traits;
      |                             ^
1 error generated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions