Bug 869194 - CheckedInt should consistently reject unsupported types - r=Waldo
authorBenoit Jacob <bjacob@mozilla.com>
Wed, 08 May 2013 17:25:15 -0400
changeset 131300 e725c1aa589dffc580c10d59829ae3a2673285bc
parent 131299 9a8c7cd83f2293987e36b1103e07d29c0263844d
child 131301 7dcb2e0f454b35b78412188cc957f39e2c016d76
push id27781
push userbjacob@mozilla.com
push dateWed, 08 May 2013 21:25:36 +0000
treeherdermozilla-inbound@e725c1aa589d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs869194
milestone23.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 869194 - CheckedInt should consistently reject unsupported types - r=Waldo
mfbt/CheckedInt.h
--- a/mfbt/CheckedInt.h
+++ b/mfbt/CheckedInt.h
@@ -556,17 +556,18 @@ class CheckedInt
 {
   protected:
     T mValue;
     bool mIsValid;
 
     template<typename U>
     CheckedInt(U value, bool isValid) : mValue(value), mIsValid(isValid)
     {
-      MOZ_STATIC_ASSERT(detail::IsSupported<T>::value,
+      MOZ_STATIC_ASSERT(detail::IsSupported<T>::value &&
+                        detail::IsSupported<U>::value,
                         "This type is not supported by CheckedInt");
     }
 
     friend class detail::NegateImpl<T>;
 
   public:
     /**
      * Constructs a checked integer with given @a value. The checked integer is
@@ -579,17 +580,18 @@ class CheckedInt
      * documentation for class CheckedInt, this constructor checks that its
      * argument is valid.
      */
     template<typename U>
     CheckedInt(U value)
       : mValue(T(value)),
         mIsValid(detail::IsInRange<T>(value))
     {
-      MOZ_STATIC_ASSERT(detail::IsSupported<T>::value,
+      MOZ_STATIC_ASSERT(detail::IsSupported<T>::value &&
+                        detail::IsSupported<U>::value,
                         "This type is not supported by CheckedInt");
     }
 
     /** Constructs a valid checked integer with initial value 0 */
     CheckedInt() : mValue(0), mIsValid(true)
     {
       MOZ_STATIC_ASSERT(detail::IsSupported<T>::value,
                         "This type is not supported by CheckedInt");
@@ -750,16 +752,19 @@ struct CastToCheckedIntImpl<T, CheckedIn
 };
 
 } // namespace detail
 
 template<typename T, typename U>
 inline typename detail::CastToCheckedIntImpl<T, U>::ReturnType
 castToCheckedInt(U u)
 {
+  MOZ_STATIC_ASSERT(detail::IsSupported<T>::value &&
+                    detail::IsSupported<U>::value,
+                    "This type is not supported by CheckedInt");
   return detail::CastToCheckedIntImpl<T, U>::run(u);
 }
 
 #define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP)  \
 template<typename T>                                              \
 template<typename U>                                              \
 CheckedInt<T>& CheckedInt<T>::operator COMPOUND_OP(U rhs)         \
 {                                                                 \