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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think the fix we want is simply:

--- a/libstdc++-v3/include/std/numeric
+++ b/libstdc++-v3/include/std/numeric
@@ -68,6 +68,7 @@
 #if __cplusplus >= 201402L
 # include <type_traits>
 # include <bit>
+# include <ext/numeric_traits.h>
 #endif

 #if __cplusplus >= 201703L
@@ -102,7 +103,15 @@ namespace __detail
       static_assert(is_unsigned<_Up>::value, "result type must be unsigned");
       static_assert(sizeof(_Up) >= sizeof(_Tp),
          "result type must be at least as wide as the input type");
-      return __val < 0 ? -(_Up)__val : (_Up)__val;
+
+      if (__val >= 0)
+       return static_cast<_Up>(__val);
+
+      if _GLIBCXX17_CONSTEXPR (sizeof(_Up) == sizeof(_Tp))
+       {
+         __glibcxx_assert(__val != __gnu_cxx::__int_traits<_Tp>::__min);
+       }
+      return -static_cast<_Up>(__val);
     }

   template<typename _Up> void __absu(bool) = delete;

Reply via email to