Bug 1350790 - Add constexpr to CheckedInt. r=froydnj
authorJW Wang <jwwang@mozilla.com>
Mon, 27 Mar 2017 10:59:31 +0800
changeset 349833 d94c51e57ea332ec674205c4ad15d1f983835529
parent 349832 d7cd2166c7a833dc722cb9e080837ea0ac1d35d2
child 349834 523fcd6d247ba99ff21539a245dce8069a6aabba
push id31562
push userkwierso@gmail.com
push dateTue, 28 Mar 2017 00:03:39 +0000
treeherdermozilla-central@a8bb5c8e0e80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1350790
milestone55.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 1350790 - Add constexpr to CheckedInt. r=froydnj MozReview-Commit-ID: KNJQcYiBlHM
mfbt/CheckedInt.h
--- a/mfbt/CheckedInt.h
+++ b/mfbt/CheckedInt.h
@@ -195,62 +195,62 @@ template<typename T,
          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)
+  static bool constexpr run(U)
   {
     return true;
   }
 };
 
 template<typename T, typename U>
 struct IsInRangeImpl<T, U, true, true, false>
 {
-  static bool run(U aX)
+  static bool constexpr run(U aX)
   {
     return aX <= MaxValue<T>::value && aX >= MinValue<T>::value;
   }
 };
 
 template<typename T, typename U>
 struct IsInRangeImpl<T, U, false, false, false>
 {
-  static bool run(U aX)
+  static bool constexpr run(U aX)
   {
     return aX <= MaxValue<T>::value;
   }
 };
 
 template<typename T, typename U>
 struct IsInRangeImpl<T, U, true, false, false>
 {
-  static bool run(U aX)
+  static bool constexpr run(U aX)
   {
     return sizeof(T) > sizeof(U) || aX <= U(MaxValue<T>::value);
   }
 };
 
 template<typename T, typename U>
 struct IsInRangeImpl<T, U, false, true, false>
 {
-  static bool run(U aX)
+  static bool constexpr run(U aX)
   {
     return sizeof(T) >= sizeof(U)
            ? aX >= 0
            : aX >= 0 && aX <= U(MaxValue<T>::value);
   }
 };
 
 template<typename T, typename U>
-inline bool
+inline constexpr bool
 IsInRange(U aX)
 {
   return IsInRangeImpl<T, U>::run(aX);
 }
 
 template<typename T>
 inline bool
 IsAddValid(T aX, T aY)
@@ -521,17 +521,17 @@ public:
    *
    * This constructor is not explicit. Instead, the type of its argument is a
    * separate template parameter, ensuring that no conversion is performed
    * before this constructor is actually called. As explained in the above
    * documentation for class CheckedInt, this constructor checks that its
    * argument is valid.
    */
   template<typename U>
-  MOZ_IMPLICIT CheckedInt(U aValue) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT
+  MOZ_IMPLICIT constexpr CheckedInt(U aValue) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT
     : mValue(T(aValue)),
       mIsValid(detail::IsInRange<T>(aValue))
   {
     static_assert(detail::IsSupported<T>::value &&
                   detail::IsSupported<U>::value,
                   "This type is not supported by CheckedInt");
   }
 
@@ -542,17 +542,17 @@ public:
   CheckedInt<U> toChecked() const
   {
     CheckedInt<U> ret(mValue);
     ret.mIsValid = ret.mIsValid && mIsValid;
     return ret;
   }
 
   /** Constructs a valid checked integer with initial value 0 */
-  CheckedInt() : mValue(0), mIsValid(true)
+  constexpr CheckedInt() : mValue(0), mIsValid(true)
   {
     static_assert(detail::IsSupported<T>::value,
                   "This type is not supported by CheckedInt");
   }
 
   /** @returns the actual value */
   T value() const
   {