]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Ensure std::make_unsigned<Enum> works for 128-bit enum
authorJonathan Wakely <jwakely@redhat.com>
Sun, 13 Jul 2025 14:05:52 +0000 (15:05 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 15 Jul 2025 09:25:39 +0000 (10:25 +0100)
Another follow-up to r16-2190-g4faa42ac0dee2c, ensuring that make_signed
and make_unsigned work on enumeration types with 128-bit integers as
their underlying type.

libstdc++-v3/ChangeLog:

* include/std/type_traits (__make_unsigned_selector): Add
unsigned __int128 to type list.
* testsuite/20_util/make_unsigned/int128.cc: New test.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/std/type_traits
libstdc++-v3/testsuite/20_util/make_unsigned/int128.cc [new file with mode: 0644]

index 78a5ee8c0eb4c820549ae70833fd00074c4ab556..ff23544fbf0311279e838cf29e8a47af98e98afe 100644 (file)
@@ -1992,8 +1992,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : __make_unsigned_selector_base
     {
       // With -fshort-enums, an enum may be as small as a char.
+      __extension__
       using _UInts = _List<unsigned char, unsigned short, unsigned int,
-                          unsigned long, unsigned long long>;
+                          unsigned long, unsigned long long
+#ifdef __SIZEOF_INT128__
+                          , unsigned __int128
+#endif
+                         >;
 
       using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
 
diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/int128.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/int128.cc
new file mode 100644 (file)
index 0000000..46c07b7
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++11 } }
+// { dg-add-options strict_std }
+
+#include <type_traits>
+
+#ifdef __SIZEOF_INT128__
+enum E : __int128 { };
+using U = std::make_unsigned<E>::type;
+static_assert( std::is_integral<U>::value, "type is an integer" );
+static_assert( sizeof(U) == sizeof(E), "width of type is 128 bits" );
+using I = std::make_signed<E>::type;
+static_assert( std::is_integral<I>::value, "type is an integer" );
+static_assert( sizeof(I) == sizeof(E), "width of type is 128 bits" );
+#endif