On Wed, Dec 17, 2025 at 07:50:16PM +0000, Jonathan Wakely wrote:
> --- a/libstdc++-v3/include/bits/random.tcc
> +++ b/libstdc++-v3/include/bits/random.tcc
> @@ -3522,10 +3522,9 @@ namespace __detail
> // r = 2; // Redundant, we only support radix 2.
> using _Rng = decltype(_Urbg::max());
> const _Rng __rng_range_less_1 = _Urbg::max() - _Urbg::min();
> - const _UInt __uint_range_less_1 = ~_UInt(0);
> // R = _UInt(__rng_range_less_1) + 1; // May wrap to 0.
> const auto __log2_R = __builtin_popcountg(__rng_range_less_1);
> - const auto __log2_uint_max = __builtin_popcountg(__uint_range_less_1);
> + const auto __log2_uint_max = __builtin_popcountg(~_UInt(0));
I don't see how this can work. __builtin_popcountg requires some integral
unsigned type, unsigned __int128 is fine, but __rand_uint128 struct is not.
So, if you want to use something like popcount, then you need some
function template which for normal unsigned integrals will return
__builtin_popcountg on the argument and for struct __rand_uint128 will
return __builtin_popcountg(_M_hi) + __builtin_popcountg(_M_lo);
> @@ -3586,25 +3585,25 @@ namespace __detail
> _RealT
> __generate_canonical_any(_Urbg& __urng)
> {
> - static_assert(__d < __builtin_popcountg(~_UInt(0)));
And if the above is changed, then this static_assert could stay.
Jakub