[PATCH 2/2] libstdc++: Ensure std::make_unsigned<Enum> works for 128-bit enum
Tomasz Kaminski
tkaminsk@redhat.com
Tue Jul 15 06:37:55 GMT 2025
On Mon, Jul 14, 2025 at 10:35 PM Jonathan Wakely <jwakely@redhat.com> wrote:
> 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.
> ---
>
> Tested x86_64-linux.
>
LGTM.
>
> libstdc++-v3/include/std/type_traits | 7 ++++++-
> .../testsuite/20_util/make_unsigned/int128.cc | 14 ++++++++++++++
> 2 files changed, 20 insertions(+), 1 deletion(-)
> create mode 100644 libstdc++-v3/testsuite/20_util/make_unsigned/int128.cc
>
> diff --git a/libstdc++-v3/include/std/type_traits
> b/libstdc++-v3/include/std/type_traits
> index 78a5ee8c0eb4..ff23544fbf03 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -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
> index 000000000000..46c07b7669e5
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/int128.cc
> @@ -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
> --
> 2.50.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250715/428db570/attachment.htm>
More information about the Libstdc++
mailing list