[WIP PATCH] libstdc++: Partially implement library part of P3666R5 - Bit-precise integers
Jakub Jelinek
jakub@redhat.com
Fri Nov 6 15:44:34 GMT 2026
Hi!
The following patch on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2026-November/737209.html
patch with minor tweaks (will post new version soon), the following
patch attempts to implement parts of the P3666R5 - Bit-precise integers
paper.
I think I got through the
[version.syn], [numeric.limits], [concepts], [climits.syn], [intseq.intseq],
[meta.trans.sign], [unord.hash], [bit] parts of the paper and tried to add
some test coverage. Note, in various tests of some function templates in
the headers signed _BitInt(1) or unsigned _BitInt(1) type can cause
occassional problems, e.g. undesirable -Wshift-count-overflow warnings etc.
signed _BitInt(1) is especially complicated, because it doesn't have
value 1 in the range, so one needs to be afraid of signed integer overflows
and extra care is needed.
The hacks to make std::make_unsigned and std::make_signed work right with
bit-precise underlying types are ugly, if you have ideas how to write
it cleaner, I'm all ears.
I wonder if we shouldn't introduce __make_signed and __make_unsigned
compiler trait, after all, clang++ already has it and for reflection
we already implement it in the compiler anyway. But still we need a
fallback, though perhaps the fallback wouldn't need to handle bit-precise
integers.
There is additional complication that clang++ at least right now doesn't
support signed _BitInt(1). I have in the patch one _BitInt(1)
specialization for __numeric_traits_integer, because min/max needs really
special care in that case, guess that would need to be guarded on
__clang__ not being defined or later on larger than whenever they actually
implement the paper. Plus if make_signed is implemented in the headers
as in the patch rather than using compiler intrinsic, the question is
what happens with clang++ unsigned _BitInt(1) which doesn't have
corresponding signed type. If we use intrinsic, it will be all clang++'s
fault.
Thoughts on this?
So far tested just on the tests I've touched, i.e.
RUNTESTFLAGS="conformance.exp='bitint* bit/*/*.cc'"
2026-11-06 Jakub Jelinek <jakub@redhat.com>
* include/bits/version.def (bit_int): New FTM.
* include/bits/version.h: Regenerate.
* include/bits/functional_hash.h (std::hash): Add _BitInt(N) and
unsigned _BitInt(N) partial specializations.
* include/bits/cpp_type_traits.h (std::__is_integer): Likewise.
* include/c_global/climits (BITINT_MAXWIDTH): Define if
__BITINT_MAXWIDTH__ is defined.
* include/ext/numeric_traits.h (__gnu_cxx::__is_integer_nonstrict):
Add _BitInt(N) and unsigned _BitInt(N) partial specializations.
(__gnu_cxx::__numeric_traits_integer): Add _BitInt(1) specialization.
* include/std/limits (std::numeric_limits): Add _BitInt(N) and
unsigned _BitInt(N) partial specializations.
* include/std/type_traits (std::__is_integral_helper): Likewise.
(std::__underlying_type_impl): Move definition earlier.
(std::__make_unsigned, std::__make_signed): Add _BitInt(N) and
unsigned _BitInt(N) partial specializations.
(std::__make_unsigned_selector_base): Change into template.
Add _BitInt(N) and unsigned _BitInt(N) partial specializations for
it.
(std::__make_unsigned_selector): Depend on
__make_unsigned_selector_base instantiation with underlying type
instead of just __make_unsigned_selector_base, adjust for dependent
base. Add another specialization for false, false.
(std::__make_unsigned<wchar_t>, std::__make_unsigned<char8_t>,
std::__make_unsigned<char16_t>, std::__make_unsigned<char32_t>):
Use __make_unsigned_selector with false, false rather than
false, true.
* include/std/bit (std::byteswap): Use __builtin_popcountg if
possible. Guard fallback on if constexpr (sizeof(_Tp) > 1).
(std::bit_compress, std::bit_expand): Guard most of the algorithm
with if constexpr (_Nd > 1).
* testsuite/18_support/headers/climits/bitint.cc: New test.
* testsuite/18_support/numeric_limits/bitint.cc: New test.
* testsuite/20_util/hash/bitint.cc: New test.
* testsuite/20_util/integer_sequence/bitint.cc: New test.
* testsuite/20_util/is_arithmetic/bitint.cc: New test.
* testsuite/20_util/is_integral/bitint.cc: New test.
* testsuite/20_util/make_signed/bitint.cc: New test.
* testsuite/20_util/make_unsigned/bitint.cc: New test.
* testsuite/26_numerics/bit/bit.byteswap/bitint.cc: New test.
* testsuite/26_numerics/bit/bit.count/countl_one.cc: Add _BitInt
tests. Guard tests which require 2+ or 8+ bit precision.
* testsuite/26_numerics/bit/bit.count/countl_zero.cc: Likewise.
* testsuite/26_numerics/bit/bit.count/countr_one.cc: Likewise.
* testsuite/26_numerics/bit/bit.count/countr_zero.cc: Likewise.
* testsuite/26_numerics/bit/bit.count/popcount.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/bit_ceil.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/bit_floor.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/bit_width.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/has_single_bit.cc: Likewise.
* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Likewise.
* testsuite/26_numerics/bit/bit.rotate/rotr.cc: Likewise.
* testsuite/26_numerics/bit/bit.shift/shl.cc: Likewise.
* testsuite/26_numerics/bit/bit.shift/shr.cc: Likewise.
* testsuite/26_numerics/bit/bit.permute/bit_compress.cc: Likewise.
* testsuite/26_numerics/bit/bit.permute/bit_expand.cc: Likewise.
* testsuite/26_numerics/bit/bit.permute/bit_repeat.cc: Likewise.
* testsuite/26_numerics/bit/bit.permute/bit_reverse.cc: Likewise.
* testsuite/std/concepts/concepts.lang/concept.arithmetic/bitint.cc:
New test.
--- a/libstdc++-v3/include/bits/version.def 2026-11-05 14:01:58.191090328 +0100
+++ b/libstdc++-v3/include/bits/version.def 2026-11-05 19:43:50.377617663 +0100
@@ -2709,6 +2709,14 @@ ftms = {
};
};
+ftms = {
+ name = bit_int;
+ values = {
+ v = 202611;
+ extra_cond = "defined(__cpp_bit_int)";
+ };
+};
+
// Standard test specifications.
stds[97] = ">= 199711L";
stds[03] = ">= 199711L";
--- a/libstdc++-v3/include/bits/version.h 2026-11-05 14:01:58.192090314 +0100
+++ b/libstdc++-v3/include/bits/version.h 2026-11-05 19:44:18.669743177 +0100
@@ -2991,4 +2991,14 @@
#endif /* !defined(__cpp_lib_hardened_view_interface) */
#undef __glibcxx_want_hardened_view_interface
+#if !defined(__cpp_lib_bit_int)
+# if (defined(__cpp_bit_int))
+# define __glibcxx_bit_int 202611L
+# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bit_int)
+# define __cpp_lib_bit_int 202611L
+# endif
+# endif
+#endif /* !defined(__cpp_lib_bit_int) */
+#undef __glibcxx_want_bit_int
+
#undef __glibcxx_want_all
--- a/libstdc++-v3/include/bits/functional_hash.h 2026-03-27 10:17:22.867188232 +0100
+++ b/libstdc++-v3/include/bits/functional_hash.h 2026-11-06 08:09:23.710634705 +0100
@@ -208,6 +208,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Cxx_hashtable_define_trivial_hash(__int128 unsigned)
#endif
+#ifdef __BITINT_MAXWIDTH__
+ template<size_t _Np>
+ struct hash<_BitInt(_Np)> : public __hash_base<size_t, _BitInt(_Np)>
+ {
+ size_t
+ operator()(_BitInt(_Np) __val) const noexcept
+ { return static_cast<size_t>(__val); }
+ };
+ template<size_t _Np>
+ struct hash<unsigned _BitInt(_Np)>
+ : public __hash_base<size_t, unsigned _BitInt(_Np)>
+ {
+ size_t
+ operator()(unsigned _BitInt(_Np) __val) const noexcept
+ { return static_cast<size_t>(__val); }
+ };
+#endif
+
#undef _Cxx_hashtable_define_trivial_hash
struct _Hash_impl
--- a/libstdc++-v3/include/bits/cpp_type_traits.h 2026-03-27 10:17:22.863188298 +0100
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h 2026-11-06 14:31:05.218748819 +0100
@@ -273,6 +273,23 @@ __INT_N(__GLIBCXX_TYPE_INT_N_2)
__INT_N(__GLIBCXX_TYPE_INT_N_3)
#endif
+#ifdef __BITINT_MAXWIDTH__
+ __extension__
+ template<size_t _Np>
+ struct __is_integer<_BitInt(_Np)>
+ {
+ enum { __value = 1 };
+ typedef __true_type __type;
+ };
+ __extension__
+ template<size_t _Np>
+ struct __is_integer<unsigned _BitInt(_Np)>
+ {
+ enum { __value = 1 };
+ typedef __true_type __type;
+ };
+#endif
+
#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__
// In strict modes __GLIBCXX_TYPE_INT_N_0 is not defined for __int128,
// but we want to always treat signed/unsigned __int128 as integral types.
--- a/libstdc++-v3/include/c_global/climits 2026-03-27 10:17:22.895187776 +0100
+++ b/libstdc++-v3/include/c_global/climits 2026-11-06 13:10:05.055412163 +0100
@@ -61,6 +61,11 @@
#define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1)
#endif
+#ifdef __BITINT_MAXWIDTH__
+# undef BITINT_MAXWIDTH
+# define BITINT_MAXWIDTH __BITINT_MAXWIDTH__
+#endif
+
#pragma GCC diagnostic pop
#endif
--- a/libstdc++-v3/include/ext/numeric_traits.h 2026-03-27 10:17:22.908187563 +0100
+++ b/libstdc++-v3/include/ext/numeric_traits.h 2026-11-06 14:17:11.719015312 +0100
@@ -126,6 +126,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_3, __GLIBCXX_BITSIZE_INT_N_3)
#endif
+#ifdef __BITINT_MAXWIDTH__
+ __extension__
+ template<std::size_t _Np>
+ struct __is_integer_nonstrict<_BitInt(_Np)>
+ {
+ enum { __value = 1 };
+ typedef std::__true_type __type;
+ enum { __width = _Np };
+ };
+ __extension__
+ template<std::size_t _Np>
+ struct __is_integer_nonstrict<unsigned _BitInt(_Np)>
+ {
+ enum { __value = 1 };
+ typedef std::__true_type __type;
+ enum { __width = _Np };
+ };
+ __extension__
+ template<>
+ struct __numeric_traits_integer<_BitInt(1)>
+ {
+ static const bool __is_signed = true;
+ static const int __digits = 0;
+ static const _BitInt(1) __max = _BitInt(1)();
+ static const _BitInt(1) __min = _BitInt(1)(-1);
+ };
+#endif
+
#undef _GLIBCXX_INT_N_TRAITS
#if __cplusplus >= 201103L
--- a/libstdc++-v3/include/std/limits 2026-05-21 16:24:39.971587563 +0200
+++ b/libstdc++-v3/include/std/limits 2026-11-05 20:09:15.690235393 +0100
@@ -1711,6 +1711,162 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#undef __INT_N_201103
#undef __INT_N_U201103
+#ifdef __BITINT_MAXWIDTH__
+ /// numeric_limits<_BitInt(N)> partial specialization.
+ template<size_t _Np>
+ struct numeric_limits<_BitInt(_Np)>
+ {
+ static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true;
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ min() _GLIBCXX_USE_NOEXCEPT
+ {
+ return _Np == 1 ? _BitInt(_Np)(-1)
+ : __glibcxx_min_b (_BitInt(_Np), _Np);
+ }
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ max() _GLIBCXX_USE_NOEXCEPT
+ {
+ return _Np == 1 ? _BitInt(_Np)(0)
+ : __glibcxx_max_b (_BitInt(_Np), _Np);
+ }
+
+#if __cplusplus >= 201103L
+ static constexpr _BitInt(_Np)
+ lowest() noexcept { return min(); }
+#endif
+
+ static _GLIBCXX_USE_CONSTEXPR int digits = _Np - 1;
+ static _GLIBCXX_USE_CONSTEXPR int digits10
+ = int(((_Np - 1) * 1936274LL) / 6432163);
+#if __cplusplus >= 201103L
+ static constexpr int max_digits10 = 0;
+#endif
+ static _GLIBCXX_USE_CONSTEXPR bool is_signed = true;
+ static _GLIBCXX_USE_CONSTEXPR bool is_integer = true;
+ static _GLIBCXX_USE_CONSTEXPR bool is_exact = true;
+ static _GLIBCXX_USE_CONSTEXPR int radix = 2;
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; }
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ round_error() _GLIBCXX_USE_NOEXCEPT { return 0; }
+
+ static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0;
+ static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0;
+ static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0;
+ static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0;
+
+ static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false;
+ static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false;
+ static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false;
+ _GLIBCXX23_DEPRECATED
+ static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm
+ = denorm_absent;
+ _GLIBCXX23_DEPRECATED
+ static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false;
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ infinity() _GLIBCXX_USE_NOEXCEPT { return _BitInt(_Np)(); }
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return _BitInt(_Np)(); }
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return _BitInt(_Np)(); }
+
+ static _GLIBCXX_CONSTEXPR _BitInt(_Np)
+ denorm_min() _GLIBCXX_USE_NOEXCEPT { return _BitInt(_Np)(); }
+
+ static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false;
+ static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true;
+ static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false;
+
+ static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps;
+ static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false;
+ static _GLIBCXX_USE_CONSTEXPR float_round_style round_style
+ = round_toward_zero;
+ };
+
+ /// numeric_limits<unsigned _BitInt(N)> partial specialization.
+ template<size_t _Np>
+ struct numeric_limits<unsigned _BitInt(_Np)>
+ {
+ static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true;
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ min() _GLIBCXX_USE_NOEXCEPT { return 0; }
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ max() _GLIBCXX_USE_NOEXCEPT
+ {
+ return __glibcxx_max_b (unsigned _BitInt(_Np), _Np);
+ }
+
+#if __cplusplus >= 201103L
+ static constexpr unsigned _BitInt(_Np)
+ lowest() noexcept { return min(); }
+#endif
+
+ static _GLIBCXX_USE_CONSTEXPR int digits = _Np;
+ static _GLIBCXX_USE_CONSTEXPR int digits10
+ = int((_Np * 1936274LL) / 6432163);
+#if __cplusplus >= 201103L
+ static constexpr int max_digits10 = 0;
+#endif
+ static _GLIBCXX_USE_CONSTEXPR bool is_signed = false;
+ static _GLIBCXX_USE_CONSTEXPR bool is_integer = true;
+ static _GLIBCXX_USE_CONSTEXPR bool is_exact = true;
+ static _GLIBCXX_USE_CONSTEXPR int radix = 2;
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; }
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ round_error() _GLIBCXX_USE_NOEXCEPT { return 0; }
+
+ static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0;
+ static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0;
+ static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0;
+ static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0;
+
+ static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false;
+ static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false;
+ static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false;
+ _GLIBCXX23_DEPRECATED
+ static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm
+ = denorm_absent;
+ _GLIBCXX23_DEPRECATED
+ static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false;
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ infinity() _GLIBCXX_USE_NOEXCEPT
+ { return static_cast<unsigned _BitInt(_Np)>(0); }
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ quiet_NaN() _GLIBCXX_USE_NOEXCEPT
+ { return static_cast<unsigned _BitInt(_Np)>(0); }
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ signaling_NaN() _GLIBCXX_USE_NOEXCEPT
+ { return static_cast<unsigned _BitInt(_Np)>(0); }
+
+ static _GLIBCXX_CONSTEXPR unsigned _BitInt(_Np)
+ denorm_min() _GLIBCXX_USE_NOEXCEPT
+ { return static_cast<unsigned _BitInt(_Np)>(0); }
+
+ static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false;
+ static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true;
+ static _GLIBCXX_USE_CONSTEXPR bool is_modulo = true;
+
+ static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps;
+ static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false;
+ static _GLIBCXX_USE_CONSTEXPR float_round_style round_style
+ = round_toward_zero;
+ };
+#endif
/// numeric_limits<float> specialization.
template<>
--- a/libstdc++-v3/include/std/type_traits 2026-11-05 14:01:58.192090314 +0100
+++ b/libstdc++-v3/include/std/type_traits 2026-11-06 09:59:57.113731987 +0100
@@ -538,6 +538,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
#endif
+#ifdef __BITINT_MAXWIDTH__
+ __extension__
+ template<size_t _Np>
+ struct __is_integral_helper<_BitInt(_Np)>
+ : public true_type
+ { static constexpr auto _S_kind = _Integer_kind::_Signed; };
+
+ __extension__
+ template<size_t _Np>
+ struct __is_integral_helper<unsigned _BitInt(_Np)>
+ : public true_type
+ { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
+#endif
+
// Check if a type is one of the signed integer types.
template<typename _Tp>
using __is_signed_integer
@@ -1959,6 +1973,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using __type = typename __match::__type;
};
+ template<typename _Tp, bool = __is_enum(_Tp)>
+ struct __underlying_type_impl
+ {
+ using type = __underlying_type(_Tp);
+ };
+
+ template<typename _Tp>
+ struct __underlying_type_impl<_Tp, false>
+ { };
+
// Utility for finding the unsigned versions of signed integral types.
template<typename _Tp>
struct __make_unsigned
@@ -2018,6 +2042,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __make_unsigned<__int128>
{ using __type = unsigned __int128; };
#endif
+#ifdef __BITINT_MAXWIDTH__
+ __extension__
+ template<size_t _Np>
+ struct __make_unsigned<_BitInt(_Np)>
+ { using __type = unsigned _BitInt(_Np); };
+#endif
// Select between integral and enum: not possible to be both.
template<typename _Tp,
@@ -2036,6 +2066,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
= typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
};
+ template<typename _Vp>
class __make_unsigned_selector_base
{
protected:
@@ -2058,21 +2089,74 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ };
};
+#ifdef __BITINT_MAXWIDTH__
+ __extension__
+ template<size_t _Np>
+ class __make_unsigned_selector_base<_BitInt(_Np)>
+ {
+ protected:
+ template<typename...> struct _List { };
+ template<size_t _Sz, typename... _UInts>
+ struct __select
+ { using __type = unsigned _BitInt(_Np); };
+ };
+
+ __extension__
+ template<size_t _Np>
+ class __make_unsigned_selector_base<unsigned _BitInt(_Np)>
+ {
+ protected:
+ template<typename...> struct _List { };
+ template<size_t _Sz, typename... _UInts>
+ struct __select
+ { using __type = unsigned _BitInt(_Np); };
+ };
+#endif
+
// Choose unsigned integer type with the smallest rank and same size as _Tp
template<typename _Tp>
class __make_unsigned_selector<_Tp, false, true>
- : __make_unsigned_selector_base
+ : __make_unsigned_selector_base<typename __underlying_type_impl<_Tp>::type>
{
// With -fshort-enums, an enum may be as small as a char.
+ using _Base
+ = __make_unsigned_selector_base<typename
+ __underlying_type_impl<_Tp>::type>;
__extension__
- using _UInts = _List<unsigned char, unsigned short, unsigned int,
- unsigned long, unsigned long long
+ using _UInts
+ = typename _Base::_List<unsigned char, unsigned short, unsigned int,
+ unsigned long, unsigned long long
#ifdef __SIZEOF_INT128__
- , unsigned __int128
+ , unsigned __int128
#endif
- >;
+ >;
- using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
+ using __unsigned_type
+ = typename _Base::__select<sizeof(_Tp), _UInts>::__type;
+
+ public:
+ using __type
+ = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
+ };
+
+ // Choose unsigned integer type with the smallest rank and same size as _Tp
+ template<typename _Tp>
+ class __make_unsigned_selector<_Tp, false, false>
+ : __make_unsigned_selector_base<_Tp>
+ {
+ // With -fshort-enums, an enum may be as small as a char.
+ using _Base = __make_unsigned_selector_base<_Tp>;
+ __extension__
+ using _UInts
+ = typename _Base::_List<unsigned char, unsigned short, unsigned int,
+ unsigned long, unsigned long long
+#ifdef __SIZEOF_INT128__
+ , unsigned __int128
+#endif
+ >;
+
+ using __unsigned_type
+ = typename _Base::__select<sizeof(_Tp), _UInts>::__type;
public:
using __type
@@ -2082,12 +2166,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// wchar_t, char8_t, char16_t and char32_t are integral types but are
// neither signed integer types nor unsigned integer types, so must be
// transformed to the unsigned integer type with the smallest rank.
- // Use the partial specialization for enumeration types to do that.
template<>
struct __make_unsigned<wchar_t>
{
using __type
- = typename __make_unsigned_selector<wchar_t, false, true>::__type;
+ = typename __make_unsigned_selector<wchar_t, false, false>::__type;
};
#ifdef _GLIBCXX_USE_CHAR8_T
@@ -2095,7 +2178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __make_unsigned<char8_t>
{
using __type
- = typename __make_unsigned_selector<char8_t, false, true>::__type;
+ = typename __make_unsigned_selector<char8_t, false, false>::__type;
};
#endif
@@ -2103,14 +2186,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __make_unsigned<char16_t>
{
using __type
- = typename __make_unsigned_selector<char16_t, false, true>::__type;
+ = typename __make_unsigned_selector<char16_t, false, false>::__type;
};
template<>
struct __make_unsigned<char32_t>
{
using __type
- = typename __make_unsigned_selector<char32_t, false, true>::__type;
+ = typename __make_unsigned_selector<char32_t, false, false>::__type;
};
/// @endcond
@@ -2189,6 +2272,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __make_signed<unsigned __int128>
{ using __type = __int128; };
#endif
+#ifdef __BITINT_MAXWIDTH__
+ __extension__
+ template<size_t _Np>
+ struct __make_signed<unsigned _BitInt(_Np)>
+ { using __type = _BitInt(_Np); };
+#endif
// Select between integral and enum: not possible to be both.
template<typename _Tp,
@@ -2711,15 +2800,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __common_type_fold<_CTp, _Rp, void>
{ };
- template<typename _Tp, bool = __is_enum(_Tp)>
- struct __underlying_type_impl
- {
- using type = __underlying_type(_Tp);
- };
-
- template<typename _Tp>
- struct __underlying_type_impl<_Tp, false>
- { };
/// @endcond
/// The underlying type of an enum.
--- a/libstdc++-v3/include/std/bit 2026-10-15 11:04:01.398021781 +0200
+++ b/libstdc++-v3/include/std/bit 2026-11-06 14:46:15.884653972 +0100
@@ -129,26 +129,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return (__builtin_bswap64(__value >> 64)
| (static_cast<_Tp>(__builtin_bswap64(__value)) << 64));
#endif
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_bswapg)
+ constexpr auto _Nd
+ = __gnu_cxx::__int_traits<__remove_cv_t<_Tp>>::__digits;
+ if constexpr (_Nd % __CHAR_BIT__ == 0)
+ {
+ using _Up = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
+ return __builtin_bswapg(_Up(__value));
+ }
+#endif
}
#endif
- // Fallback implementation that handles even __int24 etc.
- 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;
- _Up __val = __value;
- for (size_t __i = 0; __i < sizeof(_Tp) / 2; ++__i)
- {
- _Up __byte1 = __val & __mask1;
- _Up __byte2 = __val & __mask2;
- __val = (__val ^ __byte1 ^ __byte2
- ^ (__byte1 << __diff) ^ (__byte2 >> __diff));
- __mask1 <<= __CHAR_BIT__;
- __mask2 >>= __CHAR_BIT__;
- __diff -= 2 * __CHAR_BIT__;
+ if constexpr (sizeof(_Tp) > 1)
+ {
+ // Fallback implementation that handles even __int24 etc.
+ 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;
+ _Up __val = __value;
+ for (size_t __i = 0; __i < sizeof(_Tp) / 2; ++__i)
+ {
+ _Up __byte1 = __val & __mask1;
+ _Up __byte2 = __val & __mask2;
+ __val = (__val ^ __byte1 ^ __byte2
+ ^ (__byte1 << __diff) ^ (__byte2 >> __diff));
+ __mask1 <<= __CHAR_BIT__;
+ __mask2 >>= __CHAR_BIT__;
+ __diff -= 2 * __CHAR_BIT__;
+ }
+ return __val;
}
- return __val;
+ return __value;
}
#endif // __cpp_lib_byteswap
@@ -578,17 +591,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr auto _Nd = __gnu_cxx::__int_traits<_Tp>::__digits;
// Based on "Compress, or Generalized Extract" in Hacker's Delight
__x &= __m;
- _Tp __mk = ~__m << 1;
- for (int __i = 1; __i < _Nd; __i <<= 1)
+ if constexpr (_Nd > 1)
{
- _Tp __mp = __mk;
- for (int __j = 1; __j < _Nd; __j <<= 1)
- __mp ^= __mp << __j;
- _Tp __mv = __mp & __m;
- __m = (__m ^ __mv) | (__mv >> __i);
- _Tp __t = __x & __mv;
- __x = (__x ^ __t) | (__t >> __i);
- __mk = __mk & ~__mp;
+ _Tp __mk = ~__m << 1;
+ for (int __i = 1; __i < _Nd; __i <<= 1)
+ {
+ _Tp __mp = __mk;
+ for (int __j = 1; __j < _Nd; __j <<= 1)
+ __mp ^= __mp << __j;
+ _Tp __mv = __mp & __m;
+ __m = (__m ^ __mv) | (__mv >> __i);
+ _Tp __t = __x & __mv;
+ __x = (__x ^ __t) | (__t >> __i);
+ __mk = __mk & ~__mp;
+ }
}
return __x;
#endif
@@ -604,30 +620,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr auto _Nd = __gnu_cxx::__int_traits<_Tp>::__digits;
if constexpr (_Nd == 1)
return __x & __m;
- constexpr auto __log2_Nd
- = _Nd == 1 ? 1 : (__gnu_cxx::__int_traits<unsigned>::__digits
- - std::__countl_zero<unsigned>(_Nd - 1));
- // Based on "Expand, or Generalized Insert" in Hacker's Delight
- _Tp __m0 = __m;
- _Tp __mk = ~__m << 1;
- _Tp __array[__log2_Nd];
- for (int __i = 0; __i < __log2_Nd; __i++)
- {
- _Tp __mp = __mk;
- for (int __j = 1; __j < _Nd; __j <<= 1)
- __mp ^= __mp << __j;
- _Tp __mv = __mp & __m;
- __array[__i] = __mv;
- __m = (__m ^ __mv) | (__mv >> (_Tp(1) << __i));
- __mk = __mk & ~__mp;
- }
- for (int __i = __log2_Nd - 1; __i >= 0; __i--)
- {
- _Tp __mv = __array[__i];
- _Tp __t = __x << (_Tp(1) << __i);
- __x = (__x & ~__mv) | (__t & __mv);
+ else
+ {
+ constexpr auto __log2_Nd
+ = _Nd == 1 ? 1 : (__gnu_cxx::__int_traits<unsigned>::__digits
+ - std::__countl_zero<unsigned>(_Nd - 1));
+ // Based on "Expand, or Generalized Insert" in Hacker's Delight
+ _Tp __m0 = __m;
+ _Tp __mk = ~__m << 1;
+ _Tp __array[__log2_Nd];
+ for (int __i = 0; __i < __log2_Nd; __i++)
+ {
+ _Tp __mp = __mk;
+ for (int __j = 1; __j < _Nd; __j <<= 1)
+ __mp ^= __mp << __j;
+ _Tp __mv = __mp & __m;
+ __array[__i] = __mv;
+ __m = (__m ^ __mv) | (__mv >> (_Tp(1) << __i));
+ __mk = __mk & ~__mp;
+ }
+ for (int __i = __log2_Nd - 1; __i >= 0; __i--)
+ {
+ _Tp __mv = __array[__i];
+ _Tp __t = __x << (_Tp(1) << __i);
+ __x = (__x & ~__mv) | (__t & __mv);
+ }
+ return __x & __m0;
}
- return __x & __m0;
#endif
}
#endif // __cpp_lib_bitops >= 202607L
--- a/libstdc++-v3/testsuite/18_support/headers/climits/bitint.cc 2026-11-06 11:35:55.953010638 +0100
+++ b/libstdc++-v3/testsuite/18_support/headers/climits/bitint.cc 2026-11-06 11:36:50.948266435 +0100
@@ -0,0 +1,10 @@
+// { dg-do compile { target bitint } }
+
+#include <climits>
+
+#ifndef BITINT_MAXWIDTH
+#error BITINT_MAXWIDTH not defined
+#endif
+#if BITINT_MAXWIDTH != __BITINT_MAXWIDTH__
+#error unexpected value of BITINT_MAXWIDTH
+#endif
--- a/libstdc++-v3/testsuite/18_support/numeric_limits/bitint.cc 2026-11-06 10:48:49.093140440 +0100
+++ b/libstdc++-v3/testsuite/18_support/numeric_limits/bitint.cc 2026-11-06 11:18:44.683928161 +0100
@@ -0,0 +1,43 @@
+// { dg-do compile { target { c++11 && bitint } } }
+// { dg-additional-options "-Wno-c++29-extensions" { target c++26_down } }
+
+#include <limits>
+
+static_assert(std::numeric_limits<decltype(0wb)>::min() == -1, "");
+static_assert(std::numeric_limits<decltype(0wb)>::max() == 0, "");
+static_assert(std::numeric_limits<decltype(0wb)>::digits == 0, "");
+static_assert(std::numeric_limits<decltype(0wb)>::digits10 == 0, "");
+static_assert(std::numeric_limits<decltype(0wb)>::is_signed, "");
+static_assert(std::numeric_limits<decltype(0wb)>::is_integer, "");
+static_assert(std::numeric_limits<decltype(0uwb)>::min() == 0, "");
+static_assert(std::numeric_limits<decltype(0uwb)>::max() == 1, "");
+static_assert(std::numeric_limits<decltype(0uwb)>::digits == 1, "");
+static_assert(std::numeric_limits<decltype(0uwb)>::digits10 == 0, "");
+static_assert(!std::numeric_limits<decltype(0uwb)>::is_signed, "");
+static_assert(std::numeric_limits<decltype(0uwb)>::is_integer, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957wb)>::min() == -2305843009213693951wb - 1, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957wb)>::max() == 2305843009213693951wb, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957wb)>::digits == 61, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957wb)>::digits10 == 18, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957wb)>::is_signed, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957wb)>::is_integer, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957uwb)>::min() == 0, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957uwb)>::max() == 2305843009213693951uwb, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957uwb)>::digits == 61, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957uwb)>::digits10 == 18, "");
+static_assert(!std::numeric_limits<decltype(1333217576663818957uwb)>::is_signed, "");
+static_assert(std::numeric_limits<decltype(1333217576663818957uwb)>::is_integer, "");
+#if __BITINT_MAXWIDTH__ >= 132
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010wb)>::min() == -2722258935367507707706996859454145691647wb - 1, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010wb)>::max() == 2722258935367507707706996859454145691647wb, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010wb)>::digits == 131, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010wb)>::digits10 == 39, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010wb)>::is_signed, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010wb)>::is_integer, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010uwb)>::min() == 0, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010uwb)>::max() == 2722258935367507707706996859454145691647uwb, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010uwb)>::digits == 131, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010uwb)>::digits10 == 39, "");
+static_assert(!std::numeric_limits<decltype(1888966882943144259766083242878452564010uwb)>::is_signed, "");
+static_assert(std::numeric_limits<decltype(1888966882943144259766083242878452564010uwb)>::is_integer, "");
+#endif
--- a/libstdc++-v3/testsuite/20_util/hash/bitint.cc 2026-11-06 11:59:18.074947777 +0100
+++ b/libstdc++-v3/testsuite/20_util/hash/bitint.cc 2026-11-06 12:57:52.934232099 +0100
@@ -0,0 +1,23 @@
+// { dg-do run { target { c++11 && bitint } } }
+// { dg-additional-options "-Wno-c++29-extensions" { target c++26_down } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+enum E1 : _BitInt(27) {FIRST=1, SECOND=2};
+enum class E2 : unsigned _BitInt(63) {THIRD=42, FOURTH=666};
+
+int main()
+{
+ VERIFY( hash<_BitInt(27)>{}(1) == hash<E1>{}(FIRST) );
+ VERIFY( hash<_BitInt(27)>{}(2) == hash<E1>{}(SECOND) );
+ VERIFY( hash<unsigned _BitInt(63)>{}(42) == hash<E2>{}(E2::THIRD) );
+ VERIFY( hash<unsigned _BitInt(63)>{}(666) == hash<E2>{}(E2::FOURTH) );
+ VERIFY( hash<_BitInt(35)>{}(7032058851wb) == (std::size_t)7032058851wb );
+ VERIFY( hash<_BitInt(35)>{}(-7032058851wb) == (std::size_t)-7032058851wb );
+ VERIFY( hash<_BitInt(1)>{}(0wb) == (std::size_t)0wb );
+ VERIFY( hash<_BitInt(1)>{}(~0wb) == (std::size_t)~0wb );
+ VERIFY( hash<unsigned _BitInt(62)>{}(1067218502636252806uwb) == (std::size_t)1067218502636252806uwb );
+}
--- a/libstdc++-v3/testsuite/20_util/integer_sequence/bitint.cc 2026-11-06 11:48:20.959904864 +0100
+++ b/libstdc++-v3/testsuite/20_util/integer_sequence/bitint.cc 2026-11-06 13:02:01.059963316 +0100
@@ -0,0 +1,11 @@
+// { dg-do compile { target { c++14 && bitint } } }
+// { dg-additional-options "-Wno-c++29-extensions" { target c++26_down } }
+
+#include <type_traits>
+#include <utility>
+
+static_assert(std::integer_sequence<_BitInt(1)>::size() == 0, "");
+static_assert(std::integer_sequence<_BitInt(4), 4wb, 5wb, 6wb, 7wb>::size() == 4, "");
+static_assert(std::integer_sequence<unsigned _BitInt(1)>::size() == 0, "");
+static_assert(std::integer_sequence<unsigned _BitInt(1), 0uwb, 1uwb>::size() == 2, "");
+static_assert(std::integer_sequence<unsigned _BitInt(4), 13uwb, 14uwb, 15uwb>::size() == 3, "");
--- a/libstdc++-v3/testsuite/20_util/is_arithmetic/bitint.cc 2026-11-06 11:29:36.037151711 +0100
+++ b/libstdc++-v3/testsuite/20_util/is_arithmetic/bitint.cc 2026-11-06 11:31:25.309673022 +0100
@@ -0,0 +1,12 @@
+// { dg-do compile { target { c++11 && bitint } } }
+
+#include <type_traits>
+
+static_assert(std::is_arithmetic<_BitInt(1)>::value, "");
+static_assert(std::is_arithmetic<unsigned _BitInt(1)>::value, "");
+static_assert(std::is_arithmetic<signed _BitInt(57)>::value, "");
+static_assert(std::is_arithmetic<unsigned _BitInt(58)>::value, "");
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(std::is_arithmetic<signed _BitInt(574)>::value, "");
+static_assert(std::is_arithmetic<unsigned _BitInt(575)>::value, "");
+#endif
--- a/libstdc++-v3/testsuite/20_util/is_integral/bitint.cc 2026-11-06 11:29:36.037151711 +0100
+++ b/libstdc++-v3/testsuite/20_util/is_integral/bitint.cc 2026-11-06 11:30:55.436077274 +0100
@@ -0,0 +1,12 @@
+// { dg-do compile { target { c++11 && bitint } } }
+
+#include <type_traits>
+
+static_assert(std::is_integral<_BitInt(1)>::value, "");
+static_assert(std::is_integral<unsigned _BitInt(1)>::value, "");
+static_assert(std::is_integral<signed _BitInt(57)>::value, "");
+static_assert(std::is_integral<unsigned _BitInt(58)>::value, "");
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(std::is_integral<signed _BitInt(574)>::value, "");
+static_assert(std::is_integral<unsigned _BitInt(575)>::value, "");
+#endif
--- a/libstdc++-v3/testsuite/20_util/make_signed/bitint.cc 2026-11-06 10:52:25.341218388 +0100
+++ b/libstdc++-v3/testsuite/20_util/make_signed/bitint.cc 2026-11-06 11:25:13.861691637 +0100
@@ -0,0 +1,40 @@
+// { dg-do compile { target { c++11 && bitint } } }
+// { dg-additional-options "-Wno-c++29-extensions" { target c++26_down } }
+
+#include <type_traits>
+
+enum E : _BitInt(1) { E0 = -1, E1 = 0 };
+enum F : _BitInt(28) { F0 = -134217727wb - 1wb, F1 = 134217727wb };
+enum G : unsigned _BitInt(1) { G0 = 0, G1 = 1 };
+enum H : unsigned _BitInt(27) { H0 = 0wb, H1 = 134217727uwb };
+#if __BITINT_MAXWIDTH__ >= 575
+enum I : _BitInt(575) { I0 = -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb,
+ I1 = 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb };
+enum J : unsigned _BitInt(574) { J0 = 0uwb,
+ J1 = 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783uwb };
+#endif
+template<typename T>
+struct is_bitint { static constexpr bool value = false; };
+template<size_t N>
+struct is_bitint<_BitInt(N)> { static constexpr bool value = false; };
+template<size_t N>
+struct is_bitint<unsigned _BitInt(N)> { static constexpr bool value = false; };
+
+static_assert(std::is_same<std::make_signed<const _BitInt(1)>::type, const _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_signed<volatile unsigned _BitInt(1)>::type, volatile _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_signed<_BitInt(32)>::type, signed _BitInt(32)>::value, "");
+static_assert(std::is_same<std::make_signed<const volatile unsigned _BitInt(64)>::type, const volatile _BitInt(64)>::value, "");
+static_assert(std::is_same<std::make_signed<E>::type, signed _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_signed<const volatile F>::type, const volatile _BitInt(28)>::value, "");
+static_assert(std::is_same<std::make_signed<volatile G>::type, volatile _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_signed<H>::type, _BitInt(27)>::value, "");
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(std::is_same<std::make_signed<volatile _BitInt(575)>::type, volatile _BitInt(575)>::value, "");
+static_assert(std::is_same<std::make_signed<unsigned _BitInt(575)>::type, signed _BitInt(575)>::value, "");
+static_assert(std::is_same<std::make_signed<I>::type, _BitInt(575)>::value, "");
+static_assert(std::is_same<std::make_signed<const J>::type, const _BitInt(574)>::value, "");
+#endif
+static_assert(!is_bitint<std::make_signed<char8_t>::type>::value, "");
+static_assert(!is_bitint<std::make_signed<char16_t>::type>::value, "");
+static_assert(!is_bitint<std::make_signed<char32_t>::type>::value, "");
+static_assert(!is_bitint<std::make_signed<wchar_t>::type>::value, "");
--- a/libstdc++-v3/testsuite/20_util/make_unsigned/bitint.cc 2026-11-06 10:52:25.341218388 +0100
+++ b/libstdc++-v3/testsuite/20_util/make_unsigned/bitint.cc 2026-11-06 11:18:24.883194586 +0100
@@ -0,0 +1,40 @@
+// { dg-do compile { target { c++11 && bitint } } }
+// { dg-additional-options "-Wno-c++29-extensions" { target c++26_down } }
+
+#include <type_traits>
+
+enum E : _BitInt(1) { E0 = -1, E1 = 0 };
+enum F : _BitInt(28) { F0 = -134217727wb - 1wb, F1 = 134217727wb };
+enum G : unsigned _BitInt(1) { G0 = 0, G1 = 1 };
+enum H : unsigned _BitInt(27) { H0 = 0wb, H1 = 134217727uwb };
+#if __BITINT_MAXWIDTH__ >= 575
+enum I : _BitInt(575) { I0 = -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb,
+ I1 = 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb };
+enum J : unsigned _BitInt(574) { J0 = 0uwb,
+ J1 = 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783uwb };
+#endif
+template<typename T>
+struct is_bitint { static constexpr bool value = false; };
+template<size_t N>
+struct is_bitint<_BitInt(N)> { static constexpr bool value = false; };
+template<size_t N>
+struct is_bitint<unsigned _BitInt(N)> { static constexpr bool value = false; };
+
+static_assert(std::is_same<std::make_unsigned<const _BitInt(1)>::type, const unsigned _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_unsigned<volatile unsigned _BitInt(1)>::type, volatile unsigned _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_unsigned<_BitInt(32)>::type, unsigned _BitInt(32)>::value, "");
+static_assert(std::is_same<std::make_unsigned<const volatile unsigned _BitInt(64)>::type, const volatile unsigned _BitInt(64)>::value, "");
+static_assert(std::is_same<std::make_unsigned<E>::type, unsigned _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_unsigned<const volatile F>::type, const volatile unsigned _BitInt(28)>::value, "");
+static_assert(std::is_same<std::make_unsigned<volatile G>::type, volatile unsigned _BitInt(1)>::value, "");
+static_assert(std::is_same<std::make_unsigned<H>::type, unsigned _BitInt(27)>::value, "");
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(std::is_same<std::make_unsigned<volatile _BitInt(575)>::type, volatile unsigned _BitInt(575)>::value, "");
+static_assert(std::is_same<std::make_unsigned<unsigned _BitInt(575)>::type, unsigned _BitInt(575)>::value, "");
+static_assert(std::is_same<std::make_unsigned<I>::type, unsigned _BitInt(575)>::value, "");
+static_assert(std::is_same<std::make_unsigned<const J>::type, const unsigned _BitInt(574)>::value, "");
+#endif
+static_assert(!is_bitint<std::make_unsigned<char8_t>::type>::value, "");
+static_assert(!is_bitint<std::make_unsigned<char16_t>::type>::value, "");
+static_assert(!is_bitint<std::make_unsigned<char32_t>::type>::value, "");
+static_assert(!is_bitint<std::make_unsigned<wchar_t>::type>::value, "");
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.byteswap/bitint.cc 2026-11-06 12:06:35.326011348 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.byteswap/bitint.cc 2026-11-06 13:24:16.943871399 +0100
@@ -0,0 +1,70 @@
+// { dg-do compile { target c++23 } }
+// { dg-additional-options "-Wno-c++29-extensions" { target c++26_down } }
+
+#include <bit>
+
+void
+test01()
+{
+#if __CHAR_BIT__ == 8
+ static_assert( sizeof(_BitInt(8)) != 1
+ || std::byteswap<_BitInt(8)>(0x12wb) == 0x12wb );
+ static_assert( sizeof(_BitInt(16)) != 2
+ || std::byteswap<_BitInt(16)>(0x1234wb) == 0x3412wb );
+ static_assert( sizeof(_BitInt(32)) != 4
+ || std::byteswap<_BitInt(32)>(0x12345678wb) == 0x78563412wb );
+ static_assert( sizeof(_BitInt(64)) != 8
+ || (std::byteswap<_BitInt(64)>(0x123456789abcdef0wb)
+ == static_cast<_BitInt(64)>(0xf0debc9a78563412uwb)) );
+#if __BITINT_MAXWIDTH__ >= 128
+ constexpr unsigned _BitInt(128) c1 = 0x0102030405060708090a0b0c0d0e0f10uwb;
+ constexpr unsigned _BitInt(128) c2 = 0x100f0e0d0c0b0a090807060504030201uwb;
+ constexpr unsigned _BitInt(128) c3 = 0xf1e2d3c4b5a69788796a5b4c3d2e1f10uwb;
+ constexpr unsigned _BitInt(128) c4 = 0x101f2e3d4c5b6a798897a6b5c4d3e2f1uwb;
+ static_assert( sizeof(_BitInt(128)) != 16
+ || (std::byteswap<_BitInt(128)>(_BitInt(128)(c1))
+ == static_cast<_BitInt(128)>(_BitInt(128)(c2))) );
+ static_assert( sizeof(_BitInt(128)) != 16
+ || (std::byteswap<_BitInt(128)>(_BitInt(128)(c3))
+ == static_cast<_BitInt(128)>(_BitInt(128)(c4))) );
+#endif
+#if __BITINT_MAXWIDTH__ >= 512
+ constexpr unsigned _BitInt(512) c5 = 0x8d4dd94fbe44a90ed369f03356fa5f3233fd51e628240f88fddc4c1b7148d0fe96a94e54edf762c06053f4b64d53e880503a66785e76015b524d76c49547c22buwb;
+ constexpr unsigned _BitInt(512) c6 = 0x2bc24795c4764d525b01765e78663a5080e8534db6f45360c062f7ed544ea996fed048711b4cdcfd880f2428e651fd33325ffa5633f069d30ea944be4fd94d8duwb;
+ constexpr unsigned _BitInt(512) c7 = 0x6568c6970b6d341e941205ca4916145af60c1e502cb823b5c4ec62884485e1cfeda767f8159b17a9ad1c73f732875128946f79c0289c76ec88d874cc5d559c4buwb;
+ constexpr unsigned _BitInt(512) c8 = 0x4b9c555dcc74d888ec769c28c0796f9428518732f7731cada9179b15f867a7edcfe185448862ecc4b523b82c501e0cf65a141649ca0512941e346d0b97c66865uwb;
+ static_assert( sizeof(_BitInt(512)) != 64
+ || (std::byteswap<_BitInt(512)>(_BitInt(512)(c5))
+ == static_cast<_BitInt(512)>(_BitInt(512)(c6))) );
+ static_assert( sizeof(_BitInt(512)) != 64
+ || (std::byteswap<_BitInt(512)>(_BitInt(512)(c7))
+ == static_cast<_BitInt(512)>(_BitInt(512)(c8))) );
+#endif
+ static_assert( sizeof(unsigned _BitInt(8)) != 1
+ || std::byteswap<unsigned _BitInt(8)>(0x12uwb) == 0x12uwb );
+ static_assert( sizeof(unsigned _BitInt(16)) != 2
+ || std::byteswap<unsigned _BitInt(16)>(0x1234uwb) == 0x3412uwb );
+ static_assert( sizeof(unsigned _BitInt(32)) != 4
+ || std::byteswap<unsigned _BitInt(32)>(0x12345678uwb) == 0x78563412uwb );
+ static_assert( sizeof(unsigned _BitInt(64)) != 8
+ || (std::byteswap<unsigned _BitInt(64)>(0x123456789abcdef0uwb)
+ == 0xf0debc9a78563412uwb) );
+#if __BITINT_MAXWIDTH__ >= 128
+ static_assert( sizeof(unsigned _BitInt(128)) != 16
+ || std::byteswap<unsigned _BitInt(128)>(c1) == c2 );
+ static_assert( sizeof(unsigned _BitInt(128)) != 16
+ || std::byteswap<unsigned _BitInt(128)>(c3) == c4 );
+#endif
+#if __BITINT_MAXWIDTH__ >= 512
+ static_assert( sizeof(unsigned _BitInt(512)) != 64
+ || std::byteswap<unsigned _BitInt(512)>(c5) == c6 );
+ static_assert( sizeof(unsigned _BitInt(512)) != 64
+ || std::byteswap<unsigned _BitInt(512)>(c7) == c8 );
+#endif
+#endif
+}
+
+int main()
+{
+ test01();
+}
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countl_one.cc 2026-03-27 10:17:23.355180269 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countl_one.cc 2026-11-06 13:27:07.217564597 +0100
@@ -32,11 +32,14 @@ test(UInt x)
static_assert( std::countl_one((UInt)0) == 0 );
static_assert( std::countl_one((UInt)-1) == digits );
- static_assert( std::countl_one((UInt)3) == 0 );
- static_assert( std::countl_one((UInt)((UInt)1 << digits - 1)) == 1 );
- static_assert( std::countl_one((UInt)((UInt)3 << digits - 2)) == 2 );
- static_assert( std::countl_one((UInt)((UInt)7 << digits - 3)) == 3 );
- static_assert( std::countl_one((UInt)((UInt)255 << digits - 8)) == 8 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::countl_one((UInt)3) == 0 );
+ static_assert( std::countl_one((UInt)((UInt)1 << digits - 1)) == 1 );
+ static_assert( std::countl_one((UInt)((UInt)3 << digits - 2)) == 2 );
+ static_assert( std::countl_one((UInt)((UInt)7 << digits - 3)) == 3 );
+ static_assert( std::countl_one((UInt)((UInt)255 << digits - 8)) == 8 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -93,6 +96,16 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countl_zero.cc 2026-03-27 10:17:23.355180269 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countl_zero.cc 2026-11-06 13:27:28.396277671 +0100
@@ -32,9 +32,12 @@ test(UInt x)
static_assert( std::countl_zero((UInt)0) == digits );
static_assert( std::countl_zero((UInt)-1) == 0 );
- static_assert( std::countl_zero((UInt)1) == digits - 1 );
- static_assert( std::countl_zero((UInt)3) == digits - 2 );
- static_assert( std::countl_zero((UInt)0b0101'1010) == digits - 7 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::countl_zero((UInt)1) == digits - 1 );
+ static_assert( std::countl_zero((UInt)3) == digits - 2 );
+ static_assert( std::countl_zero((UInt)0b0101'1010) == digits - 7 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -90,6 +93,16 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countr_one.cc 2026-03-27 10:17:23.355180269 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countr_one.cc 2026-11-06 14:19:11.982400653 +0100
@@ -31,12 +31,16 @@ test(UInt x)
static_assert( std::countr_one((UInt)0) == 0 );
static_assert( std::countr_one((UInt)-1) == digits );
- static_assert( std::countr_one((UInt)127) == 7 );
- static_assert( std::countr_one((UInt)1) == 1 );
- static_assert( std::countr_one((UInt)3) == 2 );
- static_assert( std::countr_one((UInt)0x1f) == 5 );
- static_assert( std::countr_one((UInt)((UInt)-1 ^ 0x10)) == 4 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::countr_one((UInt)127) == 7 );
+
+ static_assert( std::countr_one((UInt)1) == 1 );
+ static_assert( std::countr_one((UInt)3) == 2 );
+ static_assert( std::countr_one((UInt)0x1f) == 5 );
+ static_assert( std::countr_one((UInt)((UInt)-1 ^ 0x10)) == 4 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -92,6 +96,16 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countr_zero.cc 2026-03-27 10:17:23.355180269 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.count/countr_zero.cc 2026-11-06 13:28:27.273480180 +0100
@@ -33,9 +33,12 @@ test(UInt x)
static_assert( std::countr_zero((UInt)-1) == 0 );
static_assert( std::countr_zero((UInt)127) == 0 );
- static_assert( std::countr_zero((UInt)1) == 0 );
- static_assert( std::countr_zero((UInt)2) == 1 );
- static_assert( std::countr_zero((UInt)0x70) == 4 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::countr_zero((UInt)1) == 0 );
+ static_assert( std::countr_zero((UInt)2) == 1 );
+ static_assert( std::countr_zero((UInt)0x70) == 4 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -91,6 +94,16 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.count/popcount.cc 2026-03-27 10:17:23.355180269 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.count/popcount.cc 2026-11-06 13:29:46.016413698 +0100
@@ -32,11 +32,14 @@ test(UInt x)
static_assert( std::popcount((UInt)0) == 0 );
static_assert( std::popcount((UInt)-1) == digits );
static_assert( std::popcount((UInt)-2) == digits - 1 );
- static_assert( std::popcount((UInt)127) == 7 );
-
static_assert( std::popcount((UInt)1) == 1 );
- static_assert( std::popcount((UInt)2) == 1 );
- static_assert( std::popcount((UInt)0x70) == 3 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::popcount((UInt)127) == 7 );
+
+ static_assert( std::popcount((UInt)2) == 1 );
+ static_assert( std::popcount((UInt)0x70) == 3 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -94,6 +97,16 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_ceil.cc 2026-03-27 10:17:23.356180253 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_ceil.cc 2026-11-06 14:55:22.303311891 +0100
@@ -44,11 +44,14 @@ test(UInt x)
static_assert( std::bit_ceil(UInt(0)) == 1 );
static_assert( std::bit_ceil(UInt(1)) == 1 );
- static_assert( std::bit_ceil(UInt(2)) == 2 );
- static_assert( std::bit_ceil(UInt(3)) == 4 );
- static_assert( std::bit_ceil(UInt(4)) == 4 );
- static_assert( std::bit_ceil(UInt(0x11)) == 0x20 );
- static_assert( std::bit_ceil(UInt(0x20)) == 0x20 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::bit_ceil(UInt(2)) == 2 );
+ static_assert( std::bit_ceil(UInt(3)) == 4 );
+ static_assert( std::bit_ceil(UInt(4)) == 4 );
+ static_assert( std::bit_ceil(UInt(0x11)) == 0x20 );
+ static_assert( std::bit_ceil(UInt(0x20)) == 0x20 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -78,10 +81,13 @@ test(UInt x)
static_assert( std::bit_ceil( UInt(msb - 3) ) == msb );
// P1355R2: not a constant expression if the result is not representable
- static_assert( !bit_ceil_valid<UInt(msb + 1)>() );
- static_assert( !bit_ceil_valid<max<UInt>>() );
- static_assert( !bit_ceil_valid<UInt(max<UInt> - 1)>() );
- static_assert( !bit_ceil_valid<UInt(max<UInt> - 2)>() );
+ if constexpr (std::numeric_limits<UInt>::digits > 1)
+ {
+ static_assert( !bit_ceil_valid<UInt(msb + 1)>() );
+ static_assert( !bit_ceil_valid<max<UInt>>() );
+ static_assert( !bit_ceil_valid<UInt(max<UInt> - 1)>() );
+ static_assert( !bit_ceil_valid<UInt(max<UInt> - 2)>() );
+ }
return true;
}
@@ -126,6 +132,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))0 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_floor.cc 2026-03-27 10:17:23.356180253 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_floor.cc 2026-11-06 14:23:40.504768667 +0100
@@ -29,11 +29,14 @@ test(UInt x)
static_assert( std::bit_floor(UInt(0)) == 0 );
static_assert( std::bit_floor(UInt(1)) == 1 );
- static_assert( std::bit_floor(UInt(2)) == 2 );
- static_assert( std::bit_floor(UInt(3)) == 2 );
- static_assert( std::bit_floor(UInt(4)) == 4 );
- static_assert( std::bit_floor(UInt(0x11)) == 0x10 );
- static_assert( std::bit_floor(UInt(0x20)) == 0x20 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::bit_floor(UInt(2)) == 2 );
+ static_assert( std::bit_floor(UInt(3)) == 2 );
+ static_assert( std::bit_floor(UInt(4)) == 4 );
+ static_assert( std::bit_floor(UInt(0x11)) == 0x10 );
+ static_assert( std::bit_floor(UInt(0x20)) == 0x20 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -98,6 +101,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))0 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_width.cc 2026-03-27 10:17:23.356180253 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/bit_width.cc 2026-11-06 14:24:03.215461248 +0100
@@ -29,11 +29,14 @@ test(UInt x)
static_assert( std::bit_width(UInt(0)) == 0 );
static_assert( std::bit_width(UInt(1)) == 1 );
- static_assert( std::bit_width(UInt(2)) == 2 );
- static_assert( std::bit_width(UInt(3)) == 2 );
- static_assert( std::bit_width(UInt(4)) == 3 );
- static_assert( std::bit_width(UInt(0x11)) == 5 );
- static_assert( std::bit_width(UInt(0x20)) == 6 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::bit_width(UInt(2)) == 2 );
+ static_assert( std::bit_width(UInt(3)) == 2 );
+ static_assert( std::bit_width(UInt(4)) == 3 );
+ static_assert( std::bit_width(UInt(0x11)) == 5 );
+ static_assert( std::bit_width(UInt(0x20)) == 6 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -98,6 +101,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))0 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/has_single_bit.cc 2026-03-27 10:17:23.356180253 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/has_single_bit.cc 2026-11-06 14:56:28.758419809 +0100
@@ -28,23 +28,30 @@ test(UInt x)
static_assert( noexcept(std::has_single_bit(x)) );
static_assert( ! std::has_single_bit( (UInt)0 ) );
- static_assert( ! std::has_single_bit( (UInt)-1 ) );
- static_assert( ! std::has_single_bit( (UInt)3 ) );
- static_assert( ! std::has_single_bit( (UInt)0x0f ) );
- static_assert( ! std::has_single_bit( (UInt)0xff ) );
- static_assert( ! std::has_single_bit( (UInt)0x0a ) );
- static_assert( ! std::has_single_bit( (UInt)0xa0 ) );
+ if constexpr (std::numeric_limits<UInt>::digits > 1)
+ static_assert( ! std::has_single_bit( (UInt)-1 ) );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( ! std::has_single_bit( (UInt)3 ) );
+ static_assert( ! std::has_single_bit( (UInt)0x0f ) );
+ static_assert( ! std::has_single_bit( (UInt)0xff ) );
+ static_assert( ! std::has_single_bit( (UInt)0x0a ) );
+ static_assert( ! std::has_single_bit( (UInt)0xa0 ) );
+ }
constexpr UInt one = 1;
static_assert( std::has_single_bit( (UInt)(one << 0) ) );
- static_assert( std::has_single_bit( (UInt)(one << 1) ) );
- static_assert( std::has_single_bit( (UInt)(one << 2) ) );
- static_assert( std::has_single_bit( (UInt)(one << 3) ) );
- static_assert( std::has_single_bit( (UInt)(one << 4) ) );
- static_assert( std::has_single_bit( (UInt)(one << 5) ) );
- static_assert( std::has_single_bit( (UInt)(one << 6) ) );
- static_assert( std::has_single_bit( (UInt)(one << 7) ) );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::has_single_bit( (UInt)(one << 1) ) );
+ static_assert( std::has_single_bit( (UInt)(one << 2) ) );
+ static_assert( std::has_single_bit( (UInt)(one << 3) ) );
+ static_assert( std::has_single_bit( (UInt)(one << 4) ) );
+ static_assert( std::has_single_bit( (UInt)(one << 5) ) );
+ static_assert( std::has_single_bit( (UInt)(one << 6) ) );
+ static_assert( std::has_single_bit( (UInt)(one << 7) ) );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -87,7 +94,8 @@ test(UInt x)
{
static_assert( std::has_single_bit( (UInt)(one << 32) ) );
static_assert( std::has_single_bit( (UInt)(one << 33) ) );
- static_assert( std::has_single_bit( (UInt)(one << 41) ) );
+ if constexpr (std::numeric_limits<UInt>::digits > 41)
+ static_assert( std::has_single_bit( (UInt)(one << 41) ) );
static_assert( ! std::has_single_bit( (UInt)((one << 32) + 1) ) );
static_assert( ! std::has_single_bit( (UInt)((one << 32) + (one << 31)) ) );
@@ -146,6 +154,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))0 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.rotate/rotl.cc 2026-03-27 10:17:23.356180253 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.rotate/rotl.cc 2026-11-06 14:27:41.183510732 +0100
@@ -53,24 +53,27 @@ test(UInt x)
static_assert( std::rotl((UInt)-1, 4) == (UInt)-1 );
static_assert( std::rotl((UInt)-1, 8) == (UInt)-1 );
- static_assert( std::rotl((UInt)1, 0) == (UInt)1 << 0 );
- static_assert( std::rotl((UInt)1, 1) == (UInt)1 << 1 );
- static_assert( std::rotl((UInt)1, 4) == (UInt)1 << 4 );
- static_assert( std::rotl((UInt)1, digits) == (UInt)1 );
- static_assert( std::rotl((UInt)7, digits) == (UInt)7 );
- static_assert( std::rotl((UInt)6, digits - 1) == (UInt)3 );
- static_assert( std::rotl((UInt)3, 6) == (UInt)3 << 6 );
-
- static_assert( std::rotl((UInt)0b0110'1100, 1) == 0b1101'1000 );
- static_assert( std::rotl((UInt)0b0110'1100, digits - 1) == 0b0011'0110 );
-
- static_assert( std::rotl((UInt)0x01, 0 ) == 0x01 );
- static_assert( std::rotl((UInt)0x10, 0 ) == 0x10 );
- static_assert( std::rotl((UInt)0x10, 1 ) == 0x20 );
- static_assert( std::rotl((UInt)0x10, 2 ) == 0x40 );
- static_assert( std::rotl((UInt)0x10, 3 ) == 0x80 );
- static_assert( std::rotl((UInt)0x11, 1 ) == 0x22 );
- static_assert( std::rotl((UInt)0x11, 2 ) == 0x44 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::rotl((UInt)1, 0) == (UInt)1 << 0 );
+ static_assert( std::rotl((UInt)1, 1) == (UInt)1 << 1 );
+ static_assert( std::rotl((UInt)1, 4) == (UInt)1 << 4 );
+ static_assert( std::rotl((UInt)1, digits) == (UInt)1 );
+ static_assert( std::rotl((UInt)7, digits) == (UInt)7 );
+ static_assert( std::rotl((UInt)6, digits - 1) == (UInt)3 );
+ static_assert( std::rotl((UInt)3, 6) == (UInt)3 << 6 );
+
+ static_assert( std::rotl((UInt)0b0110'1100, 1) == 0b1101'1000 );
+ static_assert( std::rotl((UInt)0b0110'1100, digits - 1) == 0b0011'0110 );
+
+ static_assert( std::rotl((UInt)0x01, 0 ) == 0x01 );
+ static_assert( std::rotl((UInt)0x10, 0 ) == 0x10 );
+ static_assert( std::rotl((UInt)0x10, 1 ) == 0x20 );
+ static_assert( std::rotl((UInt)0x10, 2 ) == 0x40 );
+ static_assert( std::rotl((UInt)0x10, 3 ) == 0x80 );
+ static_assert( std::rotl((UInt)0x11, 1 ) == 0x22 );
+ static_assert( std::rotl((UInt)0x11, 2 ) == 0x44 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -78,7 +81,8 @@ test(UInt x)
static_assert( std::rotl((UInt)0b1010'0101, 4) == 0b1010'0101'0000 );
}
- static_assert( test_negative_shifts<UInt>() );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ static_assert( test_negative_shifts<UInt>() );
return true;
}
@@ -123,6 +127,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))0 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.rotate/rotr.cc 2026-03-27 10:17:23.356180253 +0100
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.rotate/rotr.cc 2026-11-06 14:26:34.905407904 +0100
@@ -53,24 +53,27 @@ test(UInt x)
static_assert( std::rotr((UInt)-1, 4) == (UInt)-1 );
static_assert( std::rotr((UInt)-1, 8) == (UInt)-1 );
- static_assert( std::rotr((UInt)128, 0) == (UInt)128 >> 0 );
- static_assert( std::rotr((UInt)128, 1) == (UInt)128 >> 1 );
- static_assert( std::rotr((UInt)128, 4) == (UInt)128 >> 4 );
- static_assert( std::rotr((UInt)1, digits) == (UInt)1 );
- static_assert( std::rotr((UInt)7, digits) == (UInt)7 );
- static_assert( std::rotr((UInt)6, digits - 1) == (UInt)12 );
- static_assert( std::rotr((UInt)36, digits - 2) == (UInt)144 );
-
- static_assert( std::rotr((UInt)0b0110'1100, 1) == 0b0011'0110 );
- static_assert( std::rotr((UInt)0b0110'1100, digits - 1) == 0b1101'1000 );
-
- static_assert( std::rotr((UInt)0x01, 0 ) == 0x01 );
- static_assert( std::rotr((UInt)0x10, 0 ) == 0x10 );
- static_assert( std::rotr((UInt)0x10, 1 ) == 0x08 );
- static_assert( std::rotr((UInt)0x10, 2 ) == 0x04 );
- static_assert( std::rotr((UInt)0x10, 3 ) == 0x02 );
- static_assert( std::rotr((UInt)0x11, digits - 1 ) == 0x22 );
- static_assert( std::rotr((UInt)0x11, digits - 2 ) == 0x44 );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ {
+ static_assert( std::rotr((UInt)128, 0) == (UInt)128 >> 0 );
+ static_assert( std::rotr((UInt)128, 1) == (UInt)128 >> 1 );
+ static_assert( std::rotr((UInt)128, 4) == (UInt)128 >> 4 );
+ static_assert( std::rotr((UInt)1, digits) == (UInt)1 );
+ static_assert( std::rotr((UInt)7, digits) == (UInt)7 );
+ static_assert( std::rotr((UInt)6, digits - 1) == (UInt)12 );
+ static_assert( std::rotr((UInt)36, digits - 2) == (UInt)144 );
+
+ static_assert( std::rotr((UInt)0b0110'1100, 1) == 0b0011'0110 );
+ static_assert( std::rotr((UInt)0b0110'1100, digits - 1) == 0b1101'1000 );
+
+ static_assert( std::rotr((UInt)0x01, 0 ) == 0x01 );
+ static_assert( std::rotr((UInt)0x10, 0 ) == 0x10 );
+ static_assert( std::rotr((UInt)0x10, 1 ) == 0x08 );
+ static_assert( std::rotr((UInt)0x10, 2 ) == 0x04 );
+ static_assert( std::rotr((UInt)0x10, 3 ) == 0x02 );
+ static_assert( std::rotr((UInt)0x11, digits - 1 ) == 0x22 );
+ static_assert( std::rotr((UInt)0x11, digits - 2 ) == 0x44 );
+ }
if constexpr (std::numeric_limits<UInt>::digits > 8)
{
@@ -80,7 +83,8 @@ test(UInt x)
== (0b1010 | ((UInt)0b0101 << digits - 4)) );
}
- static_assert( test_negative_shifts<UInt>() );
+ if constexpr (std::numeric_limits<UInt>::digits >= 8)
+ static_assert( test_negative_shifts<UInt>() );
return true;
}
@@ -125,6 +129,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))0 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))0 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))0 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
#include <cstddef>
static_assert( test( (std::byte)0 ).did_not_match() );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.shift/shl.cc 2026-09-11 09:31:04.134777224 +0200
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.shift/shl.cc 2026-11-06 14:58:01.929169102 +0100
@@ -36,36 +36,45 @@ test(Int x, SInt y)
static_assert( std::shl((Int)0, (SInt)8) == 0 );
static_assert( std::shl((Int)0, (SInt)-4) == 0 );
static_assert( std::shl((Int)-1, (SInt)0) == (Int)((Int)-1 << 0) );
- static_assert( std::shl((Int)-1, (SInt)1) == (Int)((Int)-1 << 1) );
- static_assert( std::shl((Int)-1, (SInt)4) == (Int)((Int)-1 << 4) );
- static_assert( std::shl((Int)-1, (SInt)8) == (Int)((Int)-1 << 8) );
- static_assert( std::shl((Int)-1, (SInt)-4)
- == ((SInt)-4 < 0 ? (Int)-1 >> (SInt)4
- : (SInt)-4 >= digits ? 0
- : (Int)((Int)-1 << ((SInt)-4 < 0 ? 0 : (SInt)-4))) );
+ if constexpr (std::numeric_limits<Int>::digits >= 8)
+ {
+ static_assert( std::shl((Int)-1, (SInt)1) == (Int)((Int)-1 << 1) );
+ static_assert( std::shl((Int)-1, (SInt)4) == (Int)((Int)-1 << 4) );
+ static_assert( std::shl((Int)-1, (SInt)8) == (Int)((Int)-1 << 8) );
+ static_assert( std::shl((Int)-1, (SInt)-4)
+ == ((SInt)-4 < 0 ? (Int)-1 >> (SInt)4
+ : (SInt)-4 >= digits ? 0
+ : (Int)((Int)-1 << ((SInt)-4 < 0 ? 0 : (SInt)-4))) );
+ }
static_assert( std::shl((Int)1, (SInt)0) == (Int)1 << 0 );
- static_assert( std::shl((Int)1, (SInt)1) == (Int)1 << 1 );
- static_assert( std::shl((Int)1, (SInt)4) == (Int)1 << 4 );
+ if constexpr (std::numeric_limits<Int>::digits >= 8)
+ {
+ static_assert( std::shl((Int)1, (SInt)1) == (Int)1 << 1 );
+ static_assert( std::shl((Int)1, (SInt)4) == (Int)1 << 4 );
+ }
static_assert( std::shl((Int)1, (SInt)digits) == (Int)0 );
static_assert( std::shl((Int)7, (SInt)digits) == (Int)0 );
static_assert( std::shl((Int)6, (SInt)digits - 1) == (Int)0 );
- static_assert( std::shl((Int)3, (SInt)6) == (Int)((Int)3 << 6) );
+ if constexpr (std::numeric_limits<Int>::digits >= 8)
+ {
+ static_assert( std::shl((Int)3, (SInt)6) == (Int)((Int)3 << 6) );
- static_assert( std::shl((Int)0b0110'1100, (SInt)1) == (Int)0b1101'1000 );
- static_assert( std::shl((Int)0b0110'1100, (SInt)digits - 1) == 0 );
+ static_assert( std::shl((Int)0b0110'1100, (SInt)1) == (Int)0b1101'1000 );
+ static_assert( std::shl((Int)0b0110'1100, (SInt)digits - 1) == 0 );
- static_assert( std::shl((Int)0x01, (SInt)0 ) == 0x01 );
- static_assert( std::shl((Int)0x10, (SInt)0 ) == 0x10 );
- static_assert( std::shl((Int)0x10, (SInt)1 ) == 0x20 );
- static_assert( std::shl((Int)0x10, (SInt)2 ) == 0x40 );
- static_assert( std::shl((Int)0x10, (SInt)3 ) == (Int)0x80 );
- static_assert( std::shl((Int)0x11, (SInt)1 ) == 0x22 );
- static_assert( std::shl((Int)0x11, (SInt)2 ) == 0x44 );
- static_assert( std::shl((Int)0x11, (SInt)-2 )
- == ((SInt)-2 < 0 ? 4
- : (SInt)-2 >= digits ? 0
- : (Int)0x11 << ((SInt)-2 < 0 ? 0 : (SInt)-2)) );
+ static_assert( std::shl((Int)0x01, (SInt)0 ) == 0x01 );
+ static_assert( std::shl((Int)0x10, (SInt)0 ) == 0x10 );
+ static_assert( std::shl((Int)0x10, (SInt)1 ) == 0x20 );
+ static_assert( std::shl((Int)0x10, (SInt)2 ) == 0x40 );
+ static_assert( std::shl((Int)0x10, (SInt)3 ) == (Int)0x80 );
+ static_assert( std::shl((Int)0x11, (SInt)1 ) == 0x22 );
+ static_assert( std::shl((Int)0x11, (SInt)2 ) == 0x44 );
+ static_assert( std::shl((Int)0x11, (SInt)-2 )
+ == ((SInt)-2 < 0 ? 4
+ : (SInt)-2 >= digits ? 0
+ : (Int)0x11 << ((SInt)-2 < 0 ? 0 : (SInt)-2)) );
+ }
if constexpr (std::numeric_limits<Int>::digits > 8)
{
@@ -73,7 +82,9 @@ test(Int x, SInt y)
static_assert( std::shl((Int)0b1010'0101, (SInt)4) == 0b1010'0101'0000 );
}
- if constexpr (std::is_signed_v<SInt>)
+ if constexpr (std::is_signed_v<SInt>
+ && (std::numeric_limits<Int>::digits + std::is_signed_v<Int>
+ >= 8))
static_assert( test_negative_shifts<Int, SInt>() );
return true;
@@ -148,6 +159,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0, 0U ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0, 0 ) );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0, 0 ) );
+static_assert( test( (_BitInt(1))0, 0 ) );
+static_assert( test( (unsigned _BitInt(37))0, 0 ) );
+static_assert( test( (_BitInt(37))0, 0 ) );
+static_assert( test( (unsigned _BitInt(64))0, 0 ) );
+static_assert( test( (_BitInt(64))0, 0 ) );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0, 0 ) );
+static_assert( test( (_BitInt(256))0, 0 ) );
+static_assert( test( (unsigned _BitInt(575))0, 0 ) );
+static_assert( test( (_BitInt(575))0, 0 ) );
+#endif
+#endif
static_assert( std::shl(-1, 0x7fffffff00000001LL) == 0 );
static_assert( std::shl(2, 0x7fffffff00000001LL) == 0 );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.shift/shr.cc 2026-09-11 09:31:04.135941899 +0200
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.shift/shr.cc 2026-11-06 14:41:58.647030988 +0100
@@ -36,36 +36,48 @@ test(Int x, SInt y)
static_assert( std::shr((Int)0, (SInt)8) == 0 );
static_assert( std::shr((Int)0, (SInt)-4) == 0 );
static_assert( std::shr((Int)-1, (SInt)0) == (Int)((Int)-1 >> 0) );
- static_assert( std::shr((Int)-1, (SInt)1) == (Int)((Int)-1 >> 1) );
- static_assert( std::shr((Int)-1, (SInt)4) == (Int)((Int)-1 >> 4) );
- static_assert( std::shr((Int)-1, (SInt)8) == (Int)((Int)-1 >> 8) );
- static_assert( std::shr((Int)-1, (SInt)-4)
- == ((SInt)-4 < 0 ? (Int)((Int)-1 << (SInt)4)
- : (SInt)-4 >= digits ? ((Int)-1 < 0 ? (Int)-1 : 0)
- : (Int)((Int)-1 >> ((SInt)-4 < 0 ? 0 : (SInt)-4))) );
+ if constexpr (std::numeric_limits<Int>::digits >= 8)
+ {
+ static_assert( std::shr((Int)-1, (SInt)1) == (Int)((Int)-1 >> 1) );
+ static_assert( std::shr((Int)-1, (SInt)4) == (Int)((Int)-1 >> 4) );
+ static_assert( std::shr((Int)-1, (SInt)8) == (Int)((Int)-1 >> 8) );
+ static_assert( std::shr((Int)-1, (SInt)-4)
+ == ((SInt)-4 < 0 ? (Int)((Int)-1 << (SInt)4)
+ : (SInt)-4 >= digits ? ((Int)-1 < 0 ? (Int)-1 : 0)
+ : (Int)((Int)-1 >> ((SInt)-4 < 0 ? 0 : (SInt)-4))) );
+ }
static_assert( std::shr((Int)1, (SInt)0) == (Int)1 >> 0 );
- static_assert( std::shr((Int)1, (SInt)1) == (Int)1 >> 1 );
- static_assert( std::shr((Int)1, (SInt)4) == (Int)1 >> 4 );
- static_assert( std::shr((Int)1, (SInt)digits) == (Int)0 );
- static_assert( std::shr((Int)7, (SInt)digits) == (Int)0 );
+ if constexpr (std::numeric_limits<Int>::digits >= 8)
+ {
+ static_assert( std::shr((Int)1, (SInt)1) == (Int)1 >> 1 );
+ static_assert( std::shr((Int)1, (SInt)4) == (Int)1 >> 4 );
+ }
+ if constexpr (std::numeric_limits<Int>::digits > 1)
+ {
+ static_assert( std::shr((Int)1, (SInt)digits) == (Int)0 );
+ static_assert( std::shr((Int)7, (SInt)digits) == (Int)0 );
+ }
static_assert( std::shr((Int)6, (SInt)digits - 1) == (Int)0 );
- static_assert( std::shr((Int)3, (SInt)6) == (Int)((Int)3 >> 6) );
+ if constexpr (std::numeric_limits<Int>::digits >= 8)
+ {
+ static_assert( std::shr((Int)3, (SInt)6) == (Int)((Int)3 >> 6) );
- static_assert( std::shr((Int)0b0110'1100, (SInt)1) == (Int)0b0011'0110 );
- static_assert( std::shr((Int)0b0110'1100, (SInt)digits - 1) == 0 );
+ static_assert( std::shr((Int)0b0110'1100, (SInt)1) == (Int)0b0011'0110 );
+ static_assert( std::shr((Int)0b0110'1100, (SInt)digits - 1) == 0 );
- static_assert( std::shr((Int)0x01, (SInt)0 ) == 0x01 );
- static_assert( std::shr((Int)0x10, (SInt)0 ) == 0x10 );
- static_assert( std::shr((Int)0x10, (SInt)1 ) == 0x08 );
- static_assert( std::shr((Int)0x10, (SInt)2 ) == 0x04 );
- static_assert( std::shr((Int)0x10, (SInt)3 ) == 0x02 );
- static_assert( std::shr((Int)0x22, (SInt)1 ) == 0x11 );
- static_assert( std::shr((Int)0x22, (SInt)2 ) == 0x08 );
- static_assert( std::shr((Int)0x11, (SInt)-2 )
- == ((SInt)-2 < 0 ? 0x44
- : (SInt)-2 >= digits ? 0
- : (Int)0x11 >> ((SInt)-2 < 0 ? 0 : (SInt)-2)) );
+ static_assert( std::shr((Int)0x01, (SInt)0 ) == 0x01 );
+ static_assert( std::shr((Int)0x10, (SInt)0 ) == 0x10 );
+ static_assert( std::shr((Int)0x10, (SInt)1 ) == 0x08 );
+ static_assert( std::shr((Int)0x10, (SInt)2 ) == 0x04 );
+ static_assert( std::shr((Int)0x10, (SInt)3 ) == 0x02 );
+ static_assert( std::shr((Int)0x22, (SInt)1 ) == 0x11 );
+ static_assert( std::shr((Int)0x22, (SInt)2 ) == 0x08 );
+ static_assert( std::shr((Int)0x11, (SInt)-2 )
+ == ((SInt)-2 < 0 ? 0x44
+ : (SInt)-2 >= digits ? 0
+ : (Int)0x11 >> ((SInt)-2 < 0 ? 0 : (SInt)-2)) );
+ }
if constexpr (std::numeric_limits<Int>::digits > 8)
{
@@ -73,7 +85,9 @@ test(Int x, SInt y)
static_assert( std::shr((Int)0b1'1011'1000, (SInt)4) == 0b0001'1011 );
}
- if constexpr (std::is_signed_v<SInt>)
+ if constexpr (std::is_signed_v<SInt>
+ && (std::numeric_limits<Int>::digits + std::is_signed_v<Int>
+ >= 8))
static_assert( test_negative_shifts<Int, SInt>() );
return true;
@@ -148,6 +162,20 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)0, 0U ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0, 0 ) );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))0, 0 ) );
+static_assert( test( (_BitInt(1))0, 0 ) );
+static_assert( test( (unsigned _BitInt(37))0, 0 ) );
+static_assert( test( (_BitInt(37))0, 0 ) );
+static_assert( test( (unsigned _BitInt(64))0, 0 ) );
+static_assert( test( (_BitInt(64))0, 0 ) );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))0, 0 ) );
+static_assert( test( (_BitInt(256))0, 0 ) );
+static_assert( test( (unsigned _BitInt(575))0, 0 ) );
+static_assert( test( (_BitInt(575))0, 0 ) );
+#endif
+#endif
static_assert( std::shr(-1, 0x7fffffff00000001LL) == -1 );
static_assert( std::shr(2, 0x7fffffff00000001LL) == 0 );
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_compress.cc 2026-10-14 11:17:48.208748773 +0200
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_compress.cc 2026-11-06 14:38:08.118057372 +0100
@@ -14,7 +14,8 @@ test(UInt x)
static_assert( std::bit_compress(UInt(0x123456789abcdefull), UInt(~UInt(0))) == UInt(0x123456789abcdefull) );
static_assert( std::bit_compress(UInt(0), UInt(0x123456789abcdefull)) == UInt(0) );
static_assert( std::bit_compress(UInt(~UInt(0)), UInt(~UInt(0))) == UInt(~UInt(0)) );
- static_assert( std::bit_compress(UInt(~UInt(0)), UInt(0x123456789abcdefull)) == (UInt(1) << std::popcount(UInt(0x123456789abcdefull))) - 1 );
+ if constexpr (digits > 1)
+ static_assert( std::bit_compress(UInt(~UInt(0)), UInt(0x123456789abcdefull)) == (UInt(1) << std::popcount(UInt(0x123456789abcdefull))) - 1 );
static_assert( digits < 16 || digits % 2 != 0 || std::bit_compress(std::bit_repeat(UInt(0x1234), 16), std::bit_repeat(UInt(1), 2)) == std::bit_repeat(UInt(0x46), 8) >> (digits / 2) );
static_assert( digits < 16 || digits % 2 != 0 || std::bit_compress(std::bit_repeat(UInt(0x1234), 16), std::bit_repeat(UInt(2), 2)) == std::bit_repeat(UInt(0x14), 8) >> (digits / 2) );
static_assert( digits < 8 || std::bit_compress(UInt(0xff), UInt(0xff)) == UInt(0xff) );
@@ -64,7 +65,7 @@ static_assert( test( (void*)0 ).did_not_
static_assert( test( X{} ).did_not_match() );
enum E : unsigned { e };
static_assert( test( e ).did_not_match() );
-
+
#if !defined(__STRICT_ANSI__) && defined __SIZEOF_INT128__
static_assert( test( (unsigned __int128)3 ) );
static_assert( test( (__int128)0 ).did_not_match() );
@@ -85,3 +86,17 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)1 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))1 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))1 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))1 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))1 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))1 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_expand.cc 2026-10-14 11:17:48.208844129 +0200
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_expand.cc 2026-11-06 14:53:29.457829401 +0100
@@ -14,7 +14,8 @@ test(UInt x)
static_assert( std::bit_expand(UInt(0x123456789abcdefull), UInt(~UInt(0))) == UInt(0x123456789abcdefull) );
static_assert( std::bit_expand(UInt(0), UInt(0x123456789abcdefull)) == UInt(0) );
static_assert( std::bit_expand(UInt(~UInt(0)), UInt(~UInt(0))) == UInt(~UInt(0)) );
- static_assert( std::bit_expand(UInt((UInt(1) << std::popcount(UInt(0x123456789abcdefull))) - 1), UInt(0x123456789abcdefull)) == UInt(0x123456789abcdefull) );
+ if constexpr (digits > 1)
+ static_assert( std::bit_expand(UInt((UInt(1) << std::popcount(UInt(0x123456789abcdefull))) - 1), UInt(0x123456789abcdefull)) == UInt(0x123456789abcdefull) );
static_assert( digits < 16 || std::bit_expand(std::bit_repeat(UInt(0x46), 8), std::bit_repeat(UInt(1), 2)) == std::bit_repeat(UInt(0x1014), 16) );
static_assert( digits < 16 || std::bit_expand(std::bit_repeat(UInt(0x14), 8), std::bit_repeat(UInt(2), 2)) == std::bit_repeat(UInt(0x0220), 16) );
static_assert( digits < 8 || std::bit_expand(UInt(0xff), UInt(0xff)) == UInt(0xff) );
@@ -64,7 +65,7 @@ static_assert( test( (void*)0 ).did_not_
static_assert( test( X{} ).did_not_match() );
enum E : unsigned { e };
static_assert( test( e ).did_not_match() );
-
+
#if !defined(__STRICT_ANSI__) && defined __SIZEOF_INT128__
static_assert( test( (unsigned __int128)3 ) );
static_assert( test( (__int128)0 ).did_not_match() );
@@ -85,3 +86,17 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)1 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))1 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))1 ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))1 ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))1 ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))1 ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_repeat.cc 2026-10-14 11:17:48.208639977 +0200
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_repeat.cc 2026-11-06 13:31:30.871993544 +0100
@@ -102,7 +102,7 @@ static_assert( test( (void*)0 ).did_not_
static_assert( test( X{} ).did_not_match() );
enum E : unsigned { e };
static_assert( test( e ).did_not_match() );
-
+
#if !defined(__STRICT_ANSI__) && defined __SIZEOF_INT128__
static_assert( test( (unsigned __int128)3 ) );
static_assert( test( (__int128)0 ).did_not_match() );
@@ -123,3 +123,17 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)1 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))1 ) );
+static_assert( test( (_BitInt(1))1 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))1 ) );
+static_assert( test( (_BitInt(37))1 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))1 ) );
+static_assert( test( (_BitInt(64))1 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))1 ) );
+static_assert( test( (_BitInt(256))1 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))1 ) );
+static_assert( test( (_BitInt(575))1 ).did_not_match() );
+#endif
+#endif
--- a/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_reverse.cc 2026-10-14 11:17:48.208567909 +0200
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.permute/bit_reverse.cc 2026-11-06 14:02:44.750655267 +0100
@@ -50,7 +50,7 @@ static_assert( test( (void*)0 ).did_not_
static_assert( test( X{} ).did_not_match() );
enum E : unsigned { e };
static_assert( test( e ).did_not_match() );
-
+
#if !defined(__STRICT_ANSI__) && defined __SIZEOF_INT128__
static_assert( test( (unsigned __int128)3 ) );
static_assert( test( (__int128)0 ).did_not_match() );
@@ -71,3 +71,17 @@ static_assert( test( (__GLIBCXX_TYPE_INT
static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_3)1 ) );
static_assert( test( (__GLIBCXX_TYPE_INT_N_3)0 ).did_not_match() );
#endif
+#ifdef __BITINT_MAXWIDTH__
+static_assert( test( (unsigned _BitInt(1))1 ) );
+static_assert( test( (_BitInt(1))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(37))11058565729ULL ) );
+static_assert( test( (_BitInt(37))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(64))11058565729ULL ) );
+static_assert( test( (_BitInt(64))0 ).did_not_match() );
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert( test( (unsigned _BitInt(256))11058565729ULL ) );
+static_assert( test( (_BitInt(256))0 ).did_not_match() );
+static_assert( test( (unsigned _BitInt(575))11058565729ULL ) );
+static_assert( test( (_BitInt(575))0 ).did_not_match() );
+#endif
+#endif
--- a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/bitint.cc 2026-11-06 11:44:28.582072395 +0100
+++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/bitint.cc 2026-11-06 11:46:21.101538651 +0100
@@ -0,0 +1,44 @@
+// { dg-do compile { target { c++20 && bitint } } }
+
+#include <concepts>
+
+static_assert(std::integral<_BitInt(1)>);
+static_assert(std::integral<unsigned _BitInt(1)>);
+static_assert(std::integral<signed _BitInt(23)>);
+static_assert(std::integral<unsigned _BitInt(39)>);
+static_assert(std::integral<signed _BitInt(61)>);
+static_assert(std::integral<unsigned _BitInt(59)>);
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(std::integral<signed _BitInt(574)>);
+static_assert(std::integral<unsigned _BitInt(575)>);
+#endif
+static_assert(std::signed_integral<_BitInt(1)>);
+static_assert(!std::signed_integral<unsigned _BitInt(1)>);
+static_assert(std::signed_integral<signed _BitInt(23)>);
+static_assert(!std::signed_integral<unsigned _BitInt(39)>);
+static_assert(std::signed_integral<signed _BitInt(61)>);
+static_assert(!std::signed_integral<unsigned _BitInt(59)>);
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(std::signed_integral<signed _BitInt(574)>);
+static_assert(!std::signed_integral<unsigned _BitInt(575)>);
+#endif
+static_assert(!std::unsigned_integral<_BitInt(1)>);
+static_assert(std::unsigned_integral<unsigned _BitInt(1)>);
+static_assert(!std::unsigned_integral<signed _BitInt(23)>);
+static_assert(std::unsigned_integral<unsigned _BitInt(39)>);
+static_assert(!std::unsigned_integral<signed _BitInt(61)>);
+static_assert(std::unsigned_integral<unsigned _BitInt(59)>);
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(!std::unsigned_integral<signed _BitInt(574)>);
+static_assert(std::unsigned_integral<unsigned _BitInt(575)>);
+#endif
+static_assert(!std::floating_point<_BitInt(1)>);
+static_assert(!std::floating_point<unsigned _BitInt(1)>);
+static_assert(!std::floating_point<signed _BitInt(23)>);
+static_assert(!std::floating_point<unsigned _BitInt(39)>);
+static_assert(!std::floating_point<signed _BitInt(61)>);
+static_assert(!std::floating_point<unsigned _BitInt(59)>);
+#if __BITINT_MAXWIDTH__ >= 575
+static_assert(!std::floating_point<signed _BitInt(574)>);
+static_assert(!std::floating_point<unsigned _BitInt(575)>);
+#endif
Jakub
More information about the Libstdc++
mailing list