[PATCH v2] libstdc++: Fix up std::generate_canonical for 32-bit arches

Nathan Myers ncm@cantrip.org
Thu Dec 18 10:00:32 GMT 2025


On 12/18/25 4:42 AM, Jonathan Wakely wrote:
> Make use of __detail::_Select_uint_least_t<d>::type for
> std::generate_canonical, so that we choose an appropriately sized
> integer based on the number of bits needed, and so we have a 128-bit
> integer type even on 32-bit targets (via the new __rand_uint128 class).
> 
> libstdc++-v3/ChangeLog:
> 
> 	* include/bits/random.tcc (__generate_canonical_pow2): Adjust
> 	comments. Remove _UInt template parameter and define it in the
> 	body using _Select_uint_least_t<__d>. Remove popcount call for
> 	getting the width of the _UInt type. Cast floating-point
> 	literal to _RealT.
> 	(__generate_canonical_any): Remove _UInt template parameter and
> 	define it in the body using _Select_uint_least_t<__d * 2>. Use
> 	direct-initialization for _UInt variables. Cast floating-point
> 	literal to _RealT.
> 	(generate_canonical): Remove unused typedef. Remove constexpr-if
> 	branches and remove unsigned type from template argument lists.
> 
> Co-authored-by: Jakub Jelinek <jakub@redhat.com>

LGTM.



More information about the Libstdc++ mailing list