[PATCH] c++, libstdc++: Add __make_signed and __make_unsigned intrinsic traits

Jakub Jelinek jakub@redhat.com
Sat Nov 7 14:00:45 GMT 2026


Hi!

When working on the _BitInt support (but also a year ago when working
on reflection) I've noticed std::make_signed and std::make_unsigned
is implemented using a lot of templates and their specializations.

clang++ already has __make_signed/__make_unsigned intrinsic trait,
and we already implement it in the FE for reflection purposes,
so this patch adds the intrinsic traits too.
Given the clang++ naming, I've used those identifiers and not
__builtin_make_signed/__builtin_make_unsigned.
There is a small complication because <charconv> uses
__make_unsigned_selector_base for slightly different purpose, so
this patch attempts to define that class even when the intrinsic
traits are used.
Another complication is that simd_details.h was using __make_unsigned
trait instead of make_unsigned and was doing that intentionally, seems
it wants make_unsigned<_From>::type if the type is integral and
_From otherwise.  Dunno if what I wrote is the simplest.
And some libstdc++ tests were expecting exact errors while with the
builtin trait they change (if std::make_unsigned<F> is invalid, then
previously std::make_unsigned<F>::type didn't exist, now it results
in an error (unless SFINAE).

So far tested on make check-g++ with my usual 98,11,14,17,20,23,26,29
levels and make check-target-libstdc++-v3.

2026-11-07  Jakub Jelinek  <jakub@redhat.com>

gcc/cp/
	* cp-trait.def (MAKE_SIGNED, MAKE_UNSIGNED): New traits.
	* semantics.cc (finish_make_signed): New function.
	(finish_trait_type): Handle CPTK_MAKE_SIGNED and CPTK_MAKE_UNSIGNED.
	* cp-tree.h (finish_make_signed): Declare.
	* reflect.cc (eval_make_signed): Use finish_make_signed.
gcc/testsuite/
	* g++.dg/ext/has-builtin-1.C: Add __has_builtin (__make_signed)
	and __has_builtin (__make_unsigned) tests.
	* g++.dg/ext/make_signed1.C: New test.
	* g++.dg/ext/make_signed2.C: New test.
	* g++.dg/ext/make_unsigned1.C: New test.
	* g++.dg/ext/make_unsigned2.C: New test.
libstdc++-v3/
	* include/std/type_traits (std::make_unsigned, std::make_signed): Use
	__make_unsigned and __make_signed traits if possible.
	* include/std/bit (std::byteswap): Use make_unsigned rather than
	__make_unsigned.
	* include/bits/simd_details.h (std::simd::__maybe_make_unsigned): New
	trait.
	(std::simd::__value_preserving_cast): Use __maybe_make_unsigned instead
	of __make_unsigned.
	* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc: Adjust
	test for different diagnostics when using __make_signed/__make_unsigned
	traits.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Likewise.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Likewise.
	* testsuite/23_containers/mdspan/extents/class_mandates_neg.cc:
	Likewise.

--- a/gcc/cp/cp-trait.def	2026-04-08 07:49:13.472718987 +0200
+++ b/gcc/cp/cp-trait.def	2026-11-07 10:54:49.977524279 +0100
@@ -107,6 +107,8 @@ DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
 DEFTRAIT_EXPR (IS_VIRTUAL_BASE_OF, "__builtin_is_virtual_base_of", 2)
 DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1)
+DEFTRAIT_TYPE (MAKE_SIGNED, "__make_signed", 1)
+DEFTRAIT_TYPE (MAKE_UNSIGNED, "__make_unsigned", 1)
 DEFTRAIT_EXPR (RANK, "__array_rank", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
--- a/gcc/cp/semantics.cc	2026-11-06 18:32:41.085465656 +0100
+++ b/gcc/cp/semantics.cc	2026-11-07 11:18:59.196823439 +0100
@@ -5344,6 +5344,55 @@ finish_underlying_type (tree type)
   return underlying_type;
 }
 
+/* Implement the __make_signed and __make_unsigned keywords.  */
+
+tree
+finish_make_signed (tree type, bool unsignedp, tsubst_flags_t complain)
+{
+  if (!INTEGRAL_TYPE_P (type) || TREE_CODE (type) == BOOLEAN_TYPE)
+    {
+      if (complain & tf_error)
+	error ("%<make_%ssigned%> on non-integral or %<bool%> type %qT",
+	       unsignedp ? "un" : "", type);
+      return error_mark_node;
+    }
+  tree ret = type;
+  if (TREE_CODE (type) == ENUMERAL_TYPE
+      || TYPE_MAIN_VARIANT (type) == wchar_type_node
+      || TYPE_MAIN_VARIANT (type) == char8_type_node
+      || TYPE_MAIN_VARIANT (type) == char16_type_node
+      || TYPE_MAIN_VARIANT (type) == char32_type_node)
+    {
+      tree unit = TYPE_SIZE_UNIT (type);
+      tree types[] = {
+	signed_char_type_node,
+	short_integer_type_node,
+	integer_type_node,
+	long_integer_type_node,
+	long_long_integer_type_node };
+      ret = NULL_TREE;
+      for (unsigned i = 0; i < ARRAY_SIZE (types); ++i)
+	if (tree_int_cst_equal (TYPE_SIZE_UNIT (types[i]), unit))
+	  {
+	    ret = c_common_signed_or_unsigned_type (unsignedp, types[i]);
+	    break;
+	  }
+      if (!ret)
+	ret = c_common_type_for_size (TYPE_PRECISION (type), unsignedp);
+    }
+  else if (TYPE_MAIN_VARIANT (type) == char_type_node)
+    ret = unsignedp ? unsigned_char_type_node : signed_char_type_node;
+  else if (unsignedp ^ (!!TYPE_UNSIGNED (type)))
+    ret = c_common_signed_or_unsigned_type (unsignedp, type);
+  if (ret != type)
+    {
+      int quals = cp_type_quals (type);
+      quals &= (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
+      ret = cp_build_qualified_type (ret, quals);
+    }
+  return ret;
+}
+
 /* Implement the __type_pack_element keyword: Return the type
    at index IDX within TYPES.  */
 
@@ -14888,6 +14937,12 @@ finish_trait_type (cp_trait_kind kind, t
     case CPTK_UNDERLYING_TYPE:
       return finish_underlying_type (type1);
 
+    case CPTK_MAKE_SIGNED:
+      return finish_make_signed (type1, false, complain);
+
+    case CPTK_MAKE_UNSIGNED:
+      return finish_make_signed (type1, true, complain);
+
 #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
     case CPTK_##CODE:
 #include "cp-trait.def"
--- a/gcc/cp/cp-tree.h	2026-11-07 09:47:21.083490978 +0100
+++ b/gcc/cp/cp-tree.h	2026-11-07 11:17:51.297746379 +0100
@@ -8606,6 +8606,7 @@ extern cp_expr finish_id_expression		(tr
                                                  location_t);
 extern tree finish_typeof			(tree);
 extern tree finish_underlying_type	        (tree);
+extern tree finish_make_signed			(tree, bool, tsubst_flags_t);
 extern tree calculate_bases                     (tree, tsubst_flags_t);
 extern tree finish_bases                        (tree, bool);
 extern tree calculate_direct_bases              (tree, tsubst_flags_t);
--- a/gcc/cp/reflect.cc	2026-11-05 13:59:26.132122840 +0100
+++ b/gcc/cp/reflect.cc	2026-11-07 11:20:09.135872771 +0100
@@ -5528,41 +5528,8 @@ eval_make_signed (location_t loc, const
     return throw_exception (loc, ctx, "reflection represents non-integral "
 				      "or bool type", fun, non_constant_p,
 				      jump_target);
-  tree ret = type;
-  if (TREE_CODE (type) == ENUMERAL_TYPE
-      || TYPE_MAIN_VARIANT (type) == wchar_type_node
-      || TYPE_MAIN_VARIANT (type) == char8_type_node
-      || TYPE_MAIN_VARIANT (type) == char16_type_node
-      || TYPE_MAIN_VARIANT (type) == char32_type_node)
-    {
-      tree unit = TYPE_SIZE_UNIT (type);
-      tree types[] = {
-	signed_char_type_node,
-	short_integer_type_node,
-	integer_type_node,
-	long_integer_type_node,
-	long_long_integer_type_node };
-      ret = NULL_TREE;
-      for (unsigned i = 0; i < ARRAY_SIZE (types); ++i)
-	if (tree_int_cst_equal (TYPE_SIZE_UNIT (types[i]), unit))
-	  {
-	    ret = c_common_signed_or_unsigned_type (unsignedp, types[i]);
-	    break;
-	  }
-      if (!ret)
-	ret = c_common_type_for_size (TYPE_PRECISION (type), unsignedp);
-    }
-  else if (TYPE_MAIN_VARIANT (type) == char_type_node)
-    ret = unsignedp ? unsigned_char_type_node : signed_char_type_node;
-  else if (unsignedp ^ (!!TYPE_UNSIGNED (type)))
-    ret = c_common_signed_or_unsigned_type (unsignedp, type);
-  if (ret != type)
-    {
-      int quals = cp_type_quals (type);
-      quals &= (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
-      ret = cp_build_qualified_type (ret, quals);
-    }
-  else
+  tree ret = finish_make_signed (type, unsignedp, tf_warning_or_error);
+  if (ret == type)
     ret = strip_typedefs (type);
   return get_reflection_raw (loc, ret);
 }
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C	2026-03-27 10:17:15.794303651 +0100
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C	2026-11-07 11:21:06.697090353 +0100
@@ -38,6 +38,12 @@
 #if !__has_builtin (__decay)
 # error "__has_builtin (__decay) failed"
 #endif
+#if !__has_builtin (__make_signed)
+# error "__has_builtin (__make_signed) failed"
+#endif
+#if !__has_builtin (__make_unsigned)
+# error "__has_builtin (__make_unsigned) failed"
+#endif
 #if !__has_builtin (__has_nothrow_assign)
 # error "__has_builtin (__has_nothrow_assign) failed"
 #endif
--- a/gcc/testsuite/g++.dg/ext/make_signed1.C	2026-11-07 11:28:18.098230690 +0100
+++ b/gcc/testsuite/g++.dg/ext/make_signed1.C	2026-11-07 11:37:40.285602664 +0100
@@ -0,0 +1,50 @@
+// { dg-do compile { target c++11 } }
+
+enum E1 : int { E10, E11 };
+enum E2 : unsigned char { E20, E21 };
+enum E3 : short int { E30, E31 };
+enum E4 : long long { E40, E41 };
+#ifdef __SIZEOF_INT128__
+__extension__ using I128 = __int128;
+__extension__ using U128 = unsigned __int128;
+__extension__ enum E5 : I128 { E50, E51 };
+#endif
+using T1 = int;
+
+static_assert (__is_same (__make_signed (const char), const signed char), "");
+static_assert (__is_same (__make_signed (volatile signed char), volatile signed char), "");
+static_assert (__is_same (__make_signed (unsigned char), signed char), "");
+static_assert (__is_same (__make_signed (const signed short), const short), "");
+static_assert (__is_same (__make_signed (volatile unsigned short), volatile signed short), "");
+static_assert (__is_same (__make_signed (int), signed int), "");
+static_assert (__is_same (__make_signed (const unsigned int), const int), "");
+static_assert (__is_same (__make_signed (volatile long), volatile signed long), "");
+static_assert (__is_same (__make_signed (unsigned long), long), "");
+static_assert (__is_same (__make_signed (const signed long long), const long long), "");
+static_assert (__is_same (__make_signed (volatile long long unsigned), volatile long long), "");
+#ifdef __SIZEOF_INT128__
+static_assert (__is_same (__make_signed (const I128), const I128), "");
+static_assert (__is_same (__make_signed (const volatile U128), const volatile I128), "");
+#endif
+#if __SIZEOF_SHORT__ > 1 && __SIZEOF_SHORT__ < __SIZEOF_INT__ \
+    && __SIZEOF_INT__ < __SIZEOF_LONG_LONG__
+static_assert (__is_same (__make_signed (const E1), const int), "");
+static_assert (__is_same (__make_signed (volatile E2), volatile signed char), "");
+static_assert (__is_same (__make_signed (E3), short), "");
+#if __SIZEOF_LONG__ < __SIZEOF_LONG_LONG__
+static_assert (__is_same (__make_signed (const volatile E4), const volatile long long), "");
+#else
+static_assert (__is_same (__make_signed (const volatile E4), const volatile long), "");
+#endif
+#if defined(__SIZEOF_INT128__) && __SIZEOF_LONG_LONG__ < __SIZEOF_INT128__
+static_assert (__is_same (__make_signed (const E5), const I128), "");
+#endif
+#if __cpp_char8_t >= 202207L
+static_assert (__is_same (__make_signed (volatile char8_t), volatile signed char), "");
+#endif
+static_assert (sizeof (char16_t) != sizeof (short) || __is_same (__make_signed (char16_t), signed short), "");
+static_assert (sizeof (char32_t) != sizeof (int) || __is_same (__make_signed (const volatile char32_t), const volatile int), "");
+static_assert (sizeof (wchar_t) != sizeof (short) || __is_same (__make_signed (wchar_t), short), "");
+static_assert (sizeof (wchar_t) != sizeof (int) || __is_same (__make_signed (wchar_t), signed int), "");
+#endif
+static_assert (__is_same (__make_signed (T1), int), "");
--- a/gcc/testsuite/g++.dg/ext/make_unsigned1.C	2026-11-07 11:37:52.390438424 +0100
+++ b/gcc/testsuite/g++.dg/ext/make_unsigned1.C	2026-11-07 11:41:10.328752698 +0100
@@ -0,0 +1,50 @@
+// { dg-do compile { target c++11 } }
+
+enum E1 : int { E10, E11 };
+enum E2 : unsigned char { E20, E21 };
+enum E3 : short int { E30, E31 };
+enum E4 : long long { E40, E41 };
+#ifdef __SIZEOF_INT128__
+__extension__ using I128 = __int128;
+__extension__ using U128 = unsigned __int128;
+__extension__ enum E5 : I128 { E50, E51 };
+#endif
+
+static_assert (__is_same (__make_unsigned (const char), const unsigned char), "");
+static_assert (__is_same (__make_unsigned (volatile signed char), volatile unsigned char), "");
+static_assert (__is_same (__make_unsigned (unsigned char), unsigned char), "");
+static_assert (__is_same (__make_unsigned (const signed short), const unsigned short), "");
+static_assert (__is_same (__make_unsigned (volatile unsigned short), volatile unsigned short), "");
+static_assert (__is_same (__make_unsigned (int), unsigned int), "");
+static_assert (__is_same (__make_unsigned (const unsigned int), const unsigned), "");
+static_assert (__is_same (__make_unsigned (volatile long), volatile unsigned long), "");
+static_assert (__is_same (__make_unsigned (unsigned long), unsigned long), "");
+static_assert (__is_same (__make_unsigned (const signed long long), const unsigned long long), "");
+static_assert (__is_same (__make_unsigned (volatile long long unsigned), volatile unsigned long long), "");
+#ifdef __SIZEOF_INT128__
+static_assert (__is_same (__make_unsigned (const I128), const U128), "");
+static_assert (__is_same (__make_unsigned (const volatile U128), const volatile U128), "");
+#endif
+#if __SIZEOF_SHORT__ > 1 && __SIZEOF_SHORT__ < __SIZEOF_INT__ \
+    && __SIZEOF_INT__ < __SIZEOF_LONG_LONG__
+static_assert (__is_same (__make_unsigned (const E1), const unsigned int), "");
+static_assert (__is_same (__make_unsigned (volatile E2), volatile unsigned char), "");
+static_assert (__is_same (__make_unsigned (E3), unsigned short), "");
+#if __SIZEOF_LONG__ < __SIZEOF_LONG_LONG__
+static_assert (__is_same (__make_unsigned (const volatile E4), const volatile unsigned long long), "");
+#else
+static_assert (__is_same (__make_unsigned (const volatile E4), const volatile long unsigned), "");
+#endif
+#if defined(__SIZEOF_INT128__) && __SIZEOF_LONG_LONG__ < __SIZEOF_INT128__
+static_assert (__is_same (__make_unsigned (const E5), const U128), "");
+#endif
+#if __cpp_char8_t >= 202207L
+static_assert (__is_same (__make_unsigned (volatile char8_t), volatile unsigned char), "");
+#endif
+static_assert (sizeof (char16_t) != sizeof (short) || __is_same (__make_unsigned (char16_t), unsigned short), "");
+static_assert (sizeof (char32_t) != sizeof (int) || __is_same (__make_unsigned (const volatile char32_t), const volatile unsigned), "");
+static_assert (sizeof (wchar_t) != sizeof (short) || __is_same (__make_unsigned (wchar_t), unsigned short), "");
+static_assert (sizeof (wchar_t) != sizeof (int) || __is_same (__make_unsigned (wchar_t), unsigned int), "");
+#endif
+using T4 = unsigned;
+static_assert (__is_same (__make_unsigned (T4), unsigned), "");
--- a/gcc/testsuite/g++.dg/ext/make_signed2.C	2026-11-07 11:41:38.054376503 +0100
+++ b/gcc/testsuite/g++.dg/ext/make_signed2.C	2026-11-07 11:45:27.869265869 +0100
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+
+struct S;
+struct W { int w; };
+union U { int u; long v; };
+using A = __make_signed (S);		// { dg-error "'make_signed' on non-integral or 'bool' type 'S'" }
+using B = __make_signed (W);		// { dg-error "'make_signed' on non-integral or 'bool' type 'W'" }
+using C = __make_signed (U);		// { dg-error "'make_signed' on non-integral or 'bool' type 'U'" }
+using D = __make_signed (double);	// { dg-error "'make_signed' on non-integral or 'bool' type 'double'" }
+using E = __make_signed (const bool);	// { dg-error "'make_signed' on non-integral or 'bool' type 'const bool'" }
--- a/gcc/testsuite/g++.dg/ext/make_unsigned2.C	2026-11-07 11:45:36.955142988 +0100
+++ b/gcc/testsuite/g++.dg/ext/make_unsigned2.C	2026-11-07 11:45:48.459987394 +0100
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+
+struct S;
+struct W { int w; };
+union U { int u; long v; };
+using A = __make_unsigned (S);		// { dg-error "'make_unsigned' on non-integral or 'bool' type 'S'" }
+using B = __make_unsigned (W);		// { dg-error "'make_unsigned' on non-integral or 'bool' type 'W'" }
+using C = __make_unsigned (U);		// { dg-error "'make_unsigned' on non-integral or 'bool' type 'U'" }
+using D = __make_unsigned (double);	// { dg-error "'make_unsigned' on non-integral or 'bool' type 'double'" }
+using E = __make_unsigned (const bool);	// { dg-error "'make_unsigned' on non-integral or 'bool' type 'const bool'" }
--- a/libstdc++-v3/include/std/type_traits	2026-11-06 18:32:41.093465549 +0100
+++ b/libstdc++-v3/include/std/type_traits	2026-11-07 12:11:21.933366557 +0100
@@ -1960,6 +1960,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     };
 
   // Utility for finding the unsigned versions of signed integral types.
+#if !(_GLIBCXX_USE_BUILTIN_TRAIT(__make_unsigned) \
+      && _GLIBCXX_USE_BUILTIN_TRAIT(__make_signed))
   template<typename _Tp>
     struct __make_unsigned
     { using __type = _Tp; };
@@ -2035,6 +2037,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __type
 	= typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
     };
+#endif
 
   class __make_unsigned_selector_base
   {
@@ -2058,6 +2061,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { };
   };
 
+#if !(_GLIBCXX_USE_BUILTIN_TRAIT(__make_unsigned) \
+      && _GLIBCXX_USE_BUILTIN_TRAIT(__make_signed))
   // Choose unsigned integer type with the smallest rank and same size as _Tp
   template<typename _Tp>
     class __make_unsigned_selector<_Tp, false, true>
@@ -2112,12 +2117,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __type
 	= typename __make_unsigned_selector<char32_t, false, true>::__type;
     };
+#endif
   /// @endcond
 
   // Given an integral/enum type, return the corresponding unsigned
   // integer type.
   // Primary template.
   /// make_unsigned
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__make_unsigned) \
+    && _GLIBCXX_USE_BUILTIN_TRAIT(__make_signed)
+  template<typename _Tp>
+    struct make_unsigned
+    { using type = __make_unsigned(_Tp); };
+#else
   template<typename _Tp>
     struct make_unsigned
     { using type = typename __make_unsigned_selector<_Tp>::__type; };
@@ -2127,10 +2139,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<> struct make_unsigned<bool const>;
   template<> struct make_unsigned<bool volatile>;
   template<> struct make_unsigned<bool const volatile>;
-
+#endif
   /// @cond undocumented
 
   // Utility for finding the signed versions of unsigned integral types.
+#if !(_GLIBCXX_USE_BUILTIN_TRAIT(__make_unsigned) \
+      && _GLIBCXX_USE_BUILTIN_TRAIT(__make_signed))
   template<typename _Tp>
     struct __make_signed
     { using __type = _Tp; };
@@ -2250,12 +2264,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __type
 	= typename __make_signed_selector<char32_t, false, true>::__type;
     };
+#endif
   /// @endcond
 
   // Given an integral/enum type, return the corresponding signed
   // integer type.
   // Primary template.
   /// make_signed
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__make_unsigned) \
+    && _GLIBCXX_USE_BUILTIN_TRAIT(__make_signed)
+  template<typename _Tp>
+    struct make_signed
+    { using type = __make_signed(_Tp); };
+#else
   template<typename _Tp>
     struct make_signed
     { using type = typename __make_signed_selector<_Tp>::__type; };
@@ -2265,6 +2286,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<> struct make_signed<bool const>;
   template<> struct make_signed<bool volatile>;
   template<> struct make_signed<bool const volatile>;
+#endif
 
 #if __cplusplus > 201103L
   /// Alias template for make_signed
--- a/libstdc++-v3/include/std/bit	2026-11-06 18:32:41.093465549 +0100
+++ b/libstdc++-v3/include/std/bit	2026-11-07 12:13:27.048669132 +0100
@@ -133,7 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
       // Fallback implementation that handles even __int24 etc.
-      using _Up = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
+      using _Up = typename make_unsigned<__remove_cv_t<_Tp>>::type;
       size_t __diff = __CHAR_BIT__ * (sizeof(_Tp) - 1);
       _Up __mask1 = static_cast<unsigned char>(~0);
       _Up __mask2 = __mask1 << __diff;
--- a/libstdc++-v3/include/bits/simd_details.h	2026-10-27 14:32:19.785208538 +0100
+++ b/libstdc++-v3/include/bits/simd_details.h	2026-11-07 14:45:15.083892039 +0100
@@ -1313,6 +1313,12 @@ namespace simd
 #define __glibcxx_on_bad_value_preserving_cast __bad_value_preserving_cast
 #endif
 
+  template <typename _From, bool = integral<_From>>
+  struct __maybe_make_unsigned { using type = _From; };
+  template <typename _From>
+  struct __maybe_make_unsigned<_From, true>
+  { using type = make_unsigned<_From>::type; };
+
   template <typename _To, typename _From>
 #if _GLIBCXX_SIMD_THROW_ON_BAD_VALUE // see P3844
     [[__gnu__::__optimize__("exceptions")]] // work around potential -fno-exceptions
@@ -1323,7 +1329,7 @@ namespace simd
       static_assert(is_arithmetic_v<_From>);
       if constexpr (!__value_preserving_convertible_to<_From, _To>)
 	{
-	  using _Up = typename __make_unsigned<_From>::__type;
+	  using _Up = typename __maybe_make_unsigned<_From>::type;
 	  if (static_cast<_Up>(static_cast<_To>(__x)) != static_cast<_Up>(__x))
 	    __glibcxx_on_bad_value_preserving_cast();
 	  else if constexpr (is_signed_v<_From> && is_unsigned_v<_To>)
--- a/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc	2026-01-02 22:41:17.847544139 +0100
+++ b/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc	2026-11-07 13:45:32.790015266 +0100
@@ -35,7 +35,7 @@ test02()
   C c;
   std::ssize(c);  // { dg-error "no matching function" }
 }
-// { dg-error "incomplete type .*make_signed.*bool" "" { target *-*-* } 0 }
+// { dg-error "incomplete type .*make_signed.*bool|'make_signed' on non-integral or 'bool' type 'bool'" "" { target *-*-* } 0 }
 
 void
 test03()
@@ -45,4 +45,4 @@ test03()
   C c;
   std::ssize(c);  // { dg-error "no matching function" }
 }
-// { dg-error "incomplete type .*make_signed.*S" "" { target *-*-* } 0 }
+// { dg-error "incomplete type .*make_signed.*S|'make_signed' on non-integral or 'bool' type 'test03\\\(\\\)::S'" "" { target *-*-* } 0 }
--- a/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc	2026-01-02 22:41:17.878543625 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc	2026-11-07 13:42:47.401456878 +0100
@@ -53,3 +53,4 @@ test01()
 // { dg-prune-output "does not have integral type" }
 // { dg-prune-output "non-integral type" }
 // { dg-prune-output "invalid specialization" }
+// { dg-prune-output "'make_unsigned' on non-integral or 'bool' type" }
--- a/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc	2026-01-02 22:41:17.882543559 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc	2026-11-07 13:42:47.401553994 +0100
@@ -53,3 +53,5 @@ test01()
 // { dg-prune-output "does not have integral type" }
 // { dg-prune-output "non-integral type" }
 // { dg-prune-output "invalid specialization" }
+// { dg-prune-output "make_unsigned' on non-integral or 'bool' type" }
+// { dg-prune-output "argument 3 in call to function '__builtin_mul_overflow' has pointer to boolean type" }
--- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc	2026-01-02 22:41:17.729546095 +0100
+++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc	2026-11-07 13:42:47.396937588 +0100
@@ -28,10 +28,10 @@ void test01()
   using std::make_unsigned;
 
   // Negative tests.
-  using T1 = make_unsigned<bool>::type; // { dg-error "incomplete" }
-  using T2 = make_unsigned<const bool>::type; // { dg-error "incomplete" }
-  using T3 = make_unsigned<volatile bool>::type; // { dg-error "incomplete" }
-  using T4 = make_unsigned<const volatile bool>::type; // { dg-error "incomplete" }
+  using T1 = make_unsigned<bool>::type; // { dg-error "incomplete|here" }
+  using T2 = make_unsigned<const bool>::type; // { dg-error "incomplete|here" }
+  using T3 = make_unsigned<volatile bool>::type; // { dg-error "incomplete|here" }
+  using T4 = make_unsigned<const volatile bool>::type; // { dg-error "incomplete|here" }
 
   using T5 = make_unsigned<pod_class>::type; // { dg-error "here" }
 
@@ -43,4 +43,4 @@ void test01()
   using T8 = make_unsigned<float>::type; // { dg-error "here" }
 }
 
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
+// { dg-error "invalid use of incomplete type|'make_unsigned' on non-integral or 'bool' type" "" { target *-*-* } 0 }
--- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc	2026-01-02 22:41:17.729546095 +0100
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc	2026-11-07 13:42:47.396710820 +0100
@@ -28,10 +28,10 @@ void test01()
   using std::make_signed;
 
   // Negative tests.
-  using T1 = make_signed<bool>::type; // { dg-error "incomplete" }
-  using T2 = make_signed<const bool>::type; // { dg-error "incomplete" }
-  using T3 = make_signed<volatile bool>::type; // { dg-error "incomplete" }
-  using T4 = make_signed<const volatile bool>::type; // { dg-error "incomplete" }
+  using T1 = make_signed<bool>::type; // { dg-error "incomplete|here" }
+  using T2 = make_signed<const bool>::type; // { dg-error "incomplete|here" }
+  using T3 = make_signed<volatile bool>::type; // { dg-error "incomplete|here" }
+  using T4 = make_signed<const volatile bool>::type; // { dg-error "incomplete|here" }
 
   using T5 = make_signed<pod_class>::type; // { dg-error "here" }
 
@@ -43,4 +43,4 @@ void test01()
   using T8 = make_signed<float>::type; // { dg-error "here" }
 }
 
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
+// { dg-error "invalid use of incomplete type|'make_signed' on non-integral or 'bool' type" "" { target *-*-* } 0 }
--- a/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc	2025-08-23 18:15:36.412456871 +0200
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc	2026-11-07 13:42:47.398727002 +0100
@@ -15,3 +15,4 @@ std::extents<double, 1> e4;
 // { dg-prune-output "integer constants in boolean context" }
 // { dg-prune-output "__gnu_cxx::__numeric_traits_integer" }
 // { dg-prune-output "static assertion failed" }
+// { dg-prune-output "'make_unsigned' on non-integral or 'bool' type" }

	Jakub



More information about the Libstdc++ mailing list