https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113960

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1824,8 +1824,9 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
     }

 #if __cpp_lib_three_way_comparison
-  // Iter points to a contiguous range of unsigned narrow character type
-  // or std::byte, suitable for comparison by memcmp.
+  // Iter points to a contiguous range of unsigned narrow character type,
+  // or std::byte, or big-endian unsigned integers, suitable for comparison
+  // by memcmp.
   template<typename _Iter>
     concept __is_byte_iter = contiguous_iterator<_Iter>
       && __is_memcmp_ordered<iter_value_t<_Iter>>::__value;
@@ -1879,14 +1880,16 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
        if constexpr (same_as<_Comp, __detail::_Synth3way>
                      || same_as<_Comp, compare_three_way>)
          if constexpr (__is_byte_iter<_InputIter1>)
-           if constexpr (__is_byte_iter<_InputIter2>)
+           if constexpr (__is_byte_iter<_InputIter2>
+                           && sizeof(*__first1) == sizeof(*__first2))
              {
                const auto [__len, __lencmp] = _GLIBCXX_STD_A::
                  __min_cmp(__last1 - __first1, __last2 - __first2);
                if (__len)
                  {
+                   const auto __blen = __len * sizeof(*__first1);
                    const auto __c
-                     = __builtin_memcmp(&*__first1, &*__first2, __len) <=> 0;
+                     = __builtin_memcmp(&*__first1, &*__first2, __blen) <=> 0;
                    if (__c != 0)
                      return __c;
                  }

Reply via email to