Bug 768570 - Fix all the warnings in CheckedInt - r=jwalden
authorBenoit Jacob <bjacob@mozilla.com>
Thu, 05 Jul 2012 10:13:31 -0400
changeset 98379 2b9bea1ee9e94e6b020bae198e496384ba41711d
parent 98378 79f74e4d885c1616f51c33d63502b6e37f37bb1a
child 98380 8faed44d0af69183f609939637f4043f024acde0
push id11461
push userbjacob@mozilla.com
push dateThu, 05 Jul 2012 14:15:09 +0000
treeherdermozilla-inbound@bf32387bfec3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs768570
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 768570 - Fix all the warnings in CheckedInt - r=jwalden
mfbt/CheckedInt.h
mfbt/tests/TestCheckedInt.cpp
--- a/mfbt/CheckedInt.h
+++ b/mfbt/CheckedInt.h
@@ -265,47 +265,83 @@ BinaryComplement(T x)
 {
   return ~x;
 }
 
 template<typename T,
          typename U,
          bool IsTSigned = IsSigned<T>::value,
          bool IsUSigned = IsSigned<U>::value>
+struct DoesRangeContainRange
+{
+};
+
+template<typename T, typename U, bool Signedness>
+struct DoesRangeContainRange<T, U, Signedness, Signedness>
+{
+    static const bool value = sizeof(T) >= sizeof(U);
+};
+
+template<typename T, typename U>
+struct DoesRangeContainRange<T, U, true, false>
+{
+    static const bool value = sizeof(T) > sizeof(U);
+};
+
+template<typename T, typename U>
+struct DoesRangeContainRange<T, U, false, true>
+{
+    static const bool value = false;
+};
+
+template<typename T,
+         typename U,
+         bool IsTSigned = IsSigned<T>::value,
+         bool IsUSigned = IsSigned<U>::value,
+         bool DoesTRangeContainURange = DoesRangeContainRange<T, U>::value>
 struct IsInRangeImpl {};
 
+template<typename T, typename U, bool IsTSigned, bool IsUSigned>
+struct IsInRangeImpl<T, U, IsTSigned, IsUSigned, true>
+{
+    static bool run(U)
+    {
+       return true;
+    }
+};
+
 template<typename T, typename U>
-struct IsInRangeImpl<T, U, true, true>
+struct IsInRangeImpl<T, U, true, true, false>
 {
     static bool run(U x)
     {
       return x <= MaxValue<T>::value && x >= MinValue<T>::value;
     }
 };
 
 template<typename T, typename U>
-struct IsInRangeImpl<T, U, false, false>
+struct IsInRangeImpl<T, U, false, false, false>
 {
     static bool run(U x)
     {
       return x <= MaxValue<T>::value;
     }
 };
 
 template<typename T, typename U>
-struct IsInRangeImpl<T, U, true, false>
+struct IsInRangeImpl<T, U, true, false, false>
 {
     static bool run(U x)
     {
       return sizeof(T) > sizeof(U) || x <= U(MaxValue<T>::value);
     }
 };
 
 template<typename T, typename U>
-struct IsInRangeImpl<T, U, false, true>
+struct IsInRangeImpl<T, U, false, true, false>
 {
     static bool run(U x)
     {
       return sizeof(T) >= sizeof(U)
              ? x >= 0
              : x >= 0 && x <= U(MaxValue<T>::value);
     }
 };
--- a/mfbt/tests/TestCheckedInt.cpp
+++ b/mfbt/tests/TestCheckedInt.cpp
@@ -391,17 +391,17 @@ void test()
   { \
     bool isUSigned = detail::IsSigned<U>::value; \
     VERIFY_IS_VALID(CheckedInt<T>(U(0))); \
     VERIFY_IS_VALID(CheckedInt<T>(U(1))); \
     VERIFY_IS_VALID(CheckedInt<T>(U(100))); \
     if (isUSigned) \
       VERIFY_IS_VALID_IF(CheckedInt<T>(U(-1)), isTSigned); \
     if (sizeof(U) > sizeof(T)) \
-      VERIFY_IS_INVALID(CheckedInt<T>(U(detail::MaxValue<T>::value) + 1)); \
+      VERIFY_IS_INVALID(CheckedInt<T>(U(detail::MaxValue<T>::value) + one.value())); \
     VERIFY_IS_VALID_IF(CheckedInt<T>(detail::MaxValue<U>::value), \
       (sizeof(T) > sizeof(U) || ((sizeof(T) == sizeof(U)) && (isUSigned || !isTSigned)))); \
     VERIFY_IS_VALID_IF(CheckedInt<T>(detail::MinValue<U>::value), \
       isUSigned == false ? 1 : \
       bool(isTSigned) == false ? 0 : \
       sizeof(T) >= sizeof(U)); \
   }
   VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE(int8_t)