[gcc r16-8682] libstdc++: Fix philox2x64 case for 32-bit targets

Jonathan Wakely redi@gcc.gnu.org
Wed Apr 15 16:54:07 GMT 2026


https://gcc.gnu.org/g:caeab8f3594f0a34a840999b2ae05dcea518fb9c

commit r16-8682-gcaeab8f3594f0a34a840999b2ae05dcea518fb9c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 15 17:37:29 2026 +0100

    libstdc++: Fix philox2x64 case for 32-bit targets
    
    While testing a patch for std::philox_engine I noticed that
    instantiating std::philox_engine with n=2 and w=64 fails on targets
    without __int128, because it relies on an implicit conversion from the
    intermediate counter type to the result type. When w=64 and the target
    doesn't support __int128, we use the __rand_uint128 class type for the
    intermediate counter values, but that does not support implicit
    conversion to integral types.
    
    This adds the necessary casts to make the conversions explicit.
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/random.tcc (philox_engine::_M_transition): Cast
            intermediate values to result_type for n=2 case.

Diff:
---
 libstdc++-v3/include/bits/random.tcc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index 7a63e868a895..bc3393d35a89 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -966,8 +966,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  __type __num =
 		  (static_cast<__type>(_M_x[1]) << __w)
 		  | (static_cast<__type>(_M_x[0]) + 1);
-	  _M_x[0] = __num & max();
-	  _M_x[1] = (__num >> __w) & max();
+	  _M_x[0] = static_cast<_UIntType>(__num & max());
+	  _M_x[1] = static_cast<_UIntType>((__num >> __w) & max());
 	}
       _M_i = 0;
     }


More information about the Libstdc++-cvs mailing list