Index: base/numerics/safe_conversions.h |
diff --git a/base/numerics/safe_conversions.h b/base/numerics/safe_conversions.h |
index 4f45caf9c5209592f585445dee9d5fe79dfdd0b5..fb8ef09640cd9ad01133ad8bfa2e11808cad2470 100644 |
--- a/base/numerics/safe_conversions.h |
+++ b/base/numerics/safe_conversions.h |
@@ -7,10 +7,10 @@ |
#include <stddef.h> |
+#include <cassert> |
#include <limits> |
#include <type_traits> |
-#include "base/logging.h" |
#include "base/numerics/safe_conversions_impl.h" |
namespace base { |
@@ -41,11 +41,15 @@ constexpr typename std::enable_if<!std::numeric_limits<T>::is_signed, |
return false; |
} |
-// Just fires a CHECK(false). Used for numeric boundary errors. |
+// Forces a crash, like a CHECK(false). Used for numeric boundary errors. |
struct CheckOnFailure { |
template <typename T> |
static T HandleFailure() { |
- CHECK(false); |
+#if defined(__GNUC__) || defined(__clang__) |
+ __builtin_trap(); |
+#else |
+ ((void)(*(volatile char*)0 = 0)); |
Tom Sepez
2016/11/22 18:17:31
I thought we had an issue with some compiler pulli
jschuh
2016/11/22 18:27:52
This is exactly what base/logging.h uses for a CHE
|
+#endif |
return T(); |
} |
}; |
@@ -75,6 +79,7 @@ struct SaturatedCastNaNBehaviorReturnZero { |
namespace internal { |
// This wrapper is used for C++11 constexpr support by avoiding the declaration |
// of local variables in the saturated_cast template function. |
+// TODO(jschuh): convert this back to a switch once we support C++14. |
template <typename Dst, class NaNHandler, typename Src> |
constexpr Dst saturated_cast_impl(const Src value, |
const RangeConstraint constraint) { |
@@ -86,7 +91,7 @@ constexpr Dst saturated_cast_impl(const Src value, |
? std::numeric_limits<Dst>::max() |
: (constraint == RANGE_INVALID |
? NaNHandler::template HandleFailure<Dst>() |
- : (NOTREACHED(), static_cast<Dst>(value))))); |
+ : (assert(false), static_cast<Dst>(value))))); |
} |
} // namespace internal |