contour-terminal / contour

Modern C++ Terminal Emulator
http://contour-terminal.org/
Apache License 2.0
2.46k stars 107 forks source link

build failure clang-19 libc++ in StrongHash.h due to undefined template char_traits #1654

Open paparodeo opened 4 days ago

paparodeo commented 4 days ago

Contour Terminal version

0.5.1.7247

Installer source

Github: source code cloned

Operating System

macOS Sonoma 15.1.0

Architecture

AArch64

Other Software

clang-19 w/ libc++

Steps to reproduce

build with clang-19 with libc++

Expected Behavior

build succeeds

Actual Behavior

build failed

FAILED: src/vtbackend/CMakeFiles/vtbackend.dir/Grid.cpp.o 
/nix/store/dllhsrbcaxs1jh3w5zsab67fry6ijqg2-clang-wrapper-19.1.3/bin/clang++ -DCONTOUR_STACKTRACE_ADDR2LINE=1 -DHAVE_BACKTRACE -DHAVE_BACKTRACE_SYMBOLS -DHAVE_CXXABI_H -DHAVE_DLADDR -DHAVE_DLFCN_H -DHAVE_DLSYM -DHAVE_EXECINFO_H -DHAVE_SYS_SELECT_H -DHAVE_UNWIND_H -DLIBTERMINAL_LOG_TRACE=1 -DLIBTERMINAL_NAME=\"contour\" -DLIBTERMINAL_VERSION_MAJOR=0 -DLIBTERMINAL_VERSION_MINOR=5 -DLIBTERMINAL_VERSION_PATCH=1 -DLIBTERMINAL_VERSION_STRING=\"0.5.1\" -DVTPTY_LIBSSH2=1 -I/tmp/nix-build-contour-0.5.1.7247.drv-1/source/src -O3 -DNDEBUG -std=c++20 -isysroot /nix/store/amdympl4rz7kj93j82cva60v8007n4nv-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -fcolor-diagnostics -fdiagnostics-color=always -MD -MT src/vtbackend/CMakeFiles/vtbackend.dir/Grid.cpp.o -MF src/vtbackend/CMakeFiles/vtbackend.dir/Grid.cpp.o.d -o src/vtbackend/CMakeFiles/vtbackend.dir/Grid.cpp.o -c /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/Grid.cpp
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/Grid.cpp:2:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/Grid.h:4:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/GraphicsAttributes.h:4:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/CellFlags.h:4:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/crispy/flags.h:4:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/format:194:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__format/buffer.h:22:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__format/concepts.h:16:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__format/format_parse_context.h:16:
/nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/string_view:300:42: error: implicit instantiation of undefined template 'std::char_traits<unsigned int>'
  300 |   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
      |                                          ^
/tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/crispy/StrongHash.h:116:64: note: in instantiation of template class 'std::basic_string_view<unsigned int>' requested here
  116 |     return strong_hash { fnv<uint32_t, uint32_t>()(a.value[0], b.value[0]),
      |                                                                ^
/tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/crispy/StrongHash.h:116:51: note: while substituting deduced template arguments into function template 'operator()' [with V = <>]
  116 |     return strong_hash { fnv<uint32_t, uint32_t>()(a.value[0], b.value[0]),
      |                                                   ^
/nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__fwd/string.h:23:29: note: template is declared here
   23 | struct _LIBCPP_TEMPLATE_VIS char_traits;
      |                             ^
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/Grid.cpp:2:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/Grid.h:4:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/GraphicsAttributes.h:4:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/vtbackend/CellFlags.h:4:
In file included from /tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/crispy/flags.h:4:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/format:194:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__format/buffer.h:22:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__format/concepts.h:16:
In file included from /nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__format/format_parse_context.h:16:
/nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/string_view:300:42: error: implicit instantiation of undefined template 'std::char_traits<unsigned char>'
  300 |   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
      |                                          ^
/tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/crispy/FNV.h:65:38: note: in instantiation of template class 'std::basic_string_view<unsigned char>' requested here
   65 |             memory = (*this)(memory, *begin++);
      |                                      ^
/tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/crispy/FNV.h:65:22: note: while substituting deduced template arguments into function template 'operator()' [with V = <>]
   65 |             memory = (*this)(memory, *begin++);
      |                      ^
/tmp/nix-build-contour-0.5.1.7247.drv-1/source/src/crispy/StrongHash.h:194:49: note: in instantiation of member function 'crispy::fnv<unsigned char, unsigned long long>::operator()' requested here
  194 |     auto const result = fnv<uint8_t, uint64_t>()(i, e);
      |                                                 ^
/nix/store/cmn79c73agndvr3ijgs1ygfz4gw35yxv-libcxx-19.1.3-dev/include/c++/v1/__fwd/string.h:23:29: note: template is declared here
   23 | struct _LIBCPP_TEMPLATE_VIS char_traits;
      |                             ^
2 errors generated.
ninja: build stopped: subcommand failed.

Additional notes

https://libcxx.llvm.org/ReleaseNotes/19.html

The base template for std::char_traits has been removed in LLVM 19. If you are using std::char_traits with types other than char, wchar_t, char8_t, char16_t, char32_t or a custom character type for which you specialized std::char_traits, your code will stop working. The Standard does not mandate that a base template is provided, and such a base template is bound to be incorrect for some types, which could currently cause unexpected behavior while going undetected.

the following diff fixes the error.

diff --git a/src/crispy/StrongHash.h b/src/crispy/StrongHash.h
index 7a2f4e8..db5afcd 100644
--- a/src/crispy/StrongHash.h
+++ b/src/crispy/StrongHash.h
@@ -113,10 +113,10 @@ inline strong_hash operator*(strong_hash const& a, strong_hash const& b) noexcep

     return strong_hash { hashValue };
 #else
-    return strong_hash { fnv<uint32_t, uint32_t>()(a.value[0], b.value[0]),
-                         fnv<uint32_t, uint32_t>()(a.value[1], b.value[1]),
-                         fnv<uint32_t, uint32_t>()(a.value[2], b.value[2]),
-                         fnv<uint32_t, uint32_t>()(a.value[3], b.value[3]) };
+    return strong_hash { fnv<char32_t, uint32_t>()(a.value[0], b.value[0]),
+                         fnv<char32_t, uint32_t>()(a.value[1], b.value[1]),
+                         fnv<char32_t, uint32_t>()(a.value[2], b.value[2]),
+                         fnv<char32_t, uint32_t>()(a.value[3], b.value[3]) };
 #endif
 }

@@ -189,9 +189,9 @@ inline strong_hash strong_hash::compute(void const* data, size_t n) noexcept

     return strong_hash { hashValue };
 #else
-    auto const* i = (uint8_t const*) data;
+    auto const* i = (char8_t const*) data;
     auto const* e = i + n;
-    auto const result = fnv<uint8_t, uint64_t>()(i, e);
+    auto const result = fnv<char8_t, uint64_t>()(i, e);
     auto constexpr A = 0;
     auto constexpr B = 0;
     auto const c = static_cast<uint32_t>((result >> 32) & 0xFFFFFFFFu);
Yaraslaut commented 1 day ago

Hi @paparodeo, thanks a lot for the fix, we do not test compilation for most recent libc++ usually since the only platform with this beeing default is macos with always outdated library so you might encounter similar issues in the future :)