Bug 768538 - CheckedInt: HasSignBit should return bool - r=Ms2ger
authorBenoit Jacob <bjacob@mozilla.com>
Sun, 08 Jul 2012 11:44:22 -0400
changeset 98651 3cfacdaa343889a4d5dbb1f330c1640daf198e1a
parent 98650 02207487d5e52d83708325f9f881f004c2979560
child 98652 b794372c1ad2a1691b98245f009e58da44e24a7c
push idunknown
push userunknown
push dateunknown
reviewersMs2ger
bugs768538
milestone16.0a1
Bug 768538 - CheckedInt: HasSignBit should return bool - r=Ms2ger
mfbt/CheckedInt.h
--- a/mfbt/CheckedInt.h
+++ b/mfbt/CheckedInt.h
@@ -237,33 +237,30 @@ struct MaxValue
 };
 
 /*
  * Step 3: Implement the actual validity checks.
  *
  * Ideas taken from IntegerLib, code different.
  */
 
-// Bitwise ops may return a larger type, so it's good to use these inline
-// helpers guaranteeing that the result is really of type T.
-
 template<typename T>
-inline T
+inline bool
 HasSignBit(T x)
 {
   // In C++, right bit shifts on negative values is undefined by the standard.
   // Notice that signed-to-unsigned conversions are always well-defined in the
   // standard, as the value congruent modulo 2**n as expected. By contrast,
   // unsigned-to-signed is only well-defined if the value is representable.
-  // Here the unsigned-to-signed conversion is OK because the value
-  // (the result of the shift) is 0 or 1.
-  return T(typename UnsignedType<T>::Type(x)
-              >> PositionOfSignBit<T>::value);
+  return bool(typename UnsignedType<T>::Type(x)
+                >> PositionOfSignBit<T>::value);
 }
 
+// Bitwise ops may return a larger type, so it's good to use this inline
+// helper guaranteeing that the result is really of type T.
 template<typename T>
 inline T
 BinaryComplement(T x)
 {
   return ~x;
 }
 
 template<typename T,