[libcxx] r243674 - Fix PR#24267. use numeric_limits::max instead of ~0 for 'all ones', since that might give wrong answers on a 1's complement machine.

Marshall Clow mclow.lists at gmail.com
Thu Jul 30 11:26:35 PDT 2015


Author: marshall
Date: Thu Jul 30 13:26:34 2015
New Revision: 243674

URL: http://llvm.org/viewvc/llvm-project?rev=243674&view=rev
Log:
Fix PR#24267. use numeric_limits::max instead of ~0 for 'all ones', since that might give wrong answers on a 1's complement machine.

Modified:
    libcxx/trunk/include/algorithm

Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=243674&r1=243673&r2=243674&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Thu Jul 30 13:26:34 2015
@@ -3037,7 +3037,7 @@ uniform_int_distribution<_IntType>::oper
     if (_Rp == 0)
         return static_cast<result_type>(_Eng(__g, _Dt)());
     size_t __w = _Dt - __clz(_Rp) - 1;
-    if ((_Rp & (_UIntType(~0) >> (_Dt - __w))) != 0)
+    if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0)
         ++__w;
     _Eng __e(__g, __w);
     _UIntType __u;





More information about the cfe-commits mailing list