Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2211)

Unified Diff: base/numerics/safe_conversions.h

Issue 2523663002: Remove remaining base dependencies from base/numerics (Closed)
Patch Set: fix gcc compile Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/numerics/safe_math.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_conversions.h
diff --git a/base/numerics/safe_conversions.h b/base/numerics/safe_conversions.h
index 4f45caf9c5209592f585445dee9d5fe79dfdd0b5..4b9129dfffe94329c954bc1842069e7e5bd1e919 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));
+#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) {
@@ -84,9 +89,7 @@ constexpr Dst saturated_cast_impl(const Src value,
? std::numeric_limits<Dst>::min()
: (constraint == RANGE_OVERFLOW
? std::numeric_limits<Dst>::max()
- : (constraint == RANGE_INVALID
- ? NaNHandler::template HandleFailure<Dst>()
- : (NOTREACHED(), static_cast<Dst>(value)))));
+ : NaNHandler::template HandleFailure<Dst>()));
}
} // namespace internal
« no previous file with comments | « no previous file | base/numerics/safe_math.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698