Chromium Code Reviews| Index: base/numerics/safe_math_impl.h |
| diff --git a/base/numerics/safe_math_impl.h b/base/numerics/safe_math_impl.h |
| index 15de619e76fae11ce35d8ecac5b950c4e7ba432b..239c78d4d3d631bd01d9a90dbba98ce2fd853678 100644 |
| --- a/base/numerics/safe_math_impl.h |
| +++ b/base/numerics/safe_math_impl.h |
| @@ -800,19 +800,19 @@ class CheckedNumericState {}; |
| template <typename T> |
| class CheckedNumericState<T, NUMERIC_INTEGER> { |
| private: |
| - T value_; |
| bool is_valid_; |
| + T value_; |
| public: |
| template <typename Src, NumericRepresentation type> |
| friend class CheckedNumericState; |
| - constexpr CheckedNumericState() : value_(0), is_valid_(true) {} |
| + constexpr CheckedNumericState() : is_valid_(true), value_(0) {} |
| template <typename Src> |
| constexpr CheckedNumericState(Src value, bool is_valid) |
| - : value_(static_cast<T>(value)), |
| - is_valid_(is_valid && IsValueInRangeForNumericType<T>(value)) { |
| + : is_valid_(is_valid && IsValueInRangeForNumericType<T>(value)), |
| + value_(is_valid_ ? static_cast<T>(value) : 0) { |
| static_assert(std::numeric_limits<Src>::is_specialized, |
| "Argument must be numeric."); |
| } |
| @@ -820,15 +820,15 @@ class CheckedNumericState<T, NUMERIC_INTEGER> { |
| // Copy constructor. |
| template <typename Src> |
| constexpr CheckedNumericState(const CheckedNumericState<Src>& rhs) |
| - : value_(static_cast<T>(rhs.value())), is_valid_(rhs.IsValid()) {} |
| + : is_valid_(rhs.IsValid()), value_(static_cast<T>(rhs.value())) {} |
|
Nico
2016/12/02 16:46:10
This one probably needs this check too, still veri
jschuh
2016/12/02 17:19:15
Agreed, it will.
|
| template <typename Src> |
| constexpr explicit CheckedNumericState( |
| Src value, |
| typename std::enable_if<std::numeric_limits<Src>::is_specialized, |
| int>::type = 0) |
| - : value_(static_cast<T>(value)), |
| - is_valid_(IsValueInRangeForNumericType<T>(value)) {} |
| + : is_valid_(IsValueInRangeForNumericType<T>(value)), |
| + value_(is_valid_ ? static_cast<T>(value) : 0) {} |
| constexpr bool is_valid() const { return is_valid_; } |
| constexpr T value() const { return value_; } |