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.
---

Tested x86_64-linux. Pushed to trunk.

 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;
     }
-- 
2.53.0

Reply via email to