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

Unified Diff: util/stdlib/string_number_conversion.cc

Issue 615923004: Convert COMPILE_ASSERT to static_assert (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: missing include Created 6 years, 3 months 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
Index: util/stdlib/string_number_conversion.cc
diff --git a/util/stdlib/string_number_conversion.cc b/util/stdlib/string_number_conversion.cc
index 76c80fdd5ec179f6b495122f4db9bf7c72e92c6f..f96b880a0bd376f8b90ac4c61d9bcfa00a5c4377 100644
--- a/util/stdlib/string_number_conversion.cc
+++ b/util/stdlib/string_number_conversion.cc
@@ -21,20 +21,19 @@
#include <limits>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "util/stdlib/cxx.h"
-// CONSTEXPR_COMPILE_ASSERT will be a normal COMPILE_ASSERT if the C++ library
+// CONSTEXPR_STATIC_ASSERT will be a normal static_assert if the C++ library
Mark Mentovai 2014/10/01 18:57:55 Nit: this whole paragraph can reflow.
scottmg 2014/10/01 19:27:40 Done.
// is the C++11 library. If using an older C++ library when compiling C++11
// code, the std::numeric_limits<>::min() and max() functions will not be
// marked as constexpr, and thus won’t be usable with C++11’s static_assert().
// In that case, a run-time CHECK() will have to do.
#if CXX_LIBRARY_VERSION >= 2011
-#define CONSTEXPR_COMPILE_ASSERT(condition, message) \
- COMPILE_ASSERT(condition, message)
+#define CONSTEXPR_STATIC_ASSERT(condition, message) \
+ static_assert(condition, message)
#else
-#define CONSTEXPR_COMPILE_ASSERT(condition, message) CHECK(condition)
+#define CONSTEXPR_STATIC_ASSERT(condition, message) CHECK(condition) << message
#endif
namespace {
@@ -44,22 +43,22 @@ struct StringToIntegerTraits {
typedef TIntType IntType;
typedef TLongType LongType;
static void TypeCheck() {
- COMPILE_ASSERT(std::numeric_limits<TIntType>::is_integer &&
- std::numeric_limits<TLongType>::is_integer,
- IntType_and_LongType_must_be_integer);
- COMPILE_ASSERT(std::numeric_limits<TIntType>::is_signed ==
- std::numeric_limits<TLongType>::is_signed,
- IntType_and_LongType_signedness_must_agree);
- CONSTEXPR_COMPILE_ASSERT(std::numeric_limits<TIntType>::min() >=
- std::numeric_limits<TLongType>::min() &&
- std::numeric_limits<TIntType>::min() <
- std::numeric_limits<TLongType>::max(),
- IntType_min_must_be_in_LongType_range);
- CONSTEXPR_COMPILE_ASSERT(std::numeric_limits<TIntType>::max() >
- std::numeric_limits<TLongType>::min() &&
- std::numeric_limits<TIntType>::max() <=
- std::numeric_limits<TLongType>::max(),
- IntType_max_must_be_in_LongType_range);
+ static_assert(std::numeric_limits<TIntType>::is_integer &&
+ std::numeric_limits<TLongType>::is_integer,
+ "IntType and LongType must be integer");
+ static_assert(std::numeric_limits<TIntType>::is_signed ==
+ std::numeric_limits<TLongType>::is_signed,
+ "IntType and LongType signedness must agree");
+ CONSTEXPR_STATIC_ASSERT(std::numeric_limits<TIntType>::min() >=
+ std::numeric_limits<TLongType>::min() &&
+ std::numeric_limits<TIntType>::min() <
+ std::numeric_limits<TLongType>::max(),
+ "IntType min must be in LongType range");
+ CONSTEXPR_STATIC_ASSERT(std::numeric_limits<TIntType>::max() >
+ std::numeric_limits<TLongType>::min() &&
+ std::numeric_limits<TIntType>::max() <=
+ std::numeric_limits<TLongType>::max(),
+ "IntType max must be in LongType range");
}
};
@@ -67,8 +66,8 @@ template <typename TIntType, typename TLongType>
struct StringToSignedIntegerTraits
: public StringToIntegerTraits<TIntType, TLongType> {
static void TypeCheck() {
- COMPILE_ASSERT(std::numeric_limits<TIntType>::is_signed,
- StringToSignedTraits_IntType_must_be_signed);
+ static_assert(std::numeric_limits<TIntType>::is_signed,
+ "StringToSignedTraits IntType must be signed");
return super::TypeCheck();
}
static bool IsNegativeOverflow(TLongType value) {
@@ -83,8 +82,8 @@ template <typename TIntType, typename TLongType>
struct StringToUnsignedIntegerTraits
: public StringToIntegerTraits<TIntType, TLongType> {
static void TypeCheck() {
- COMPILE_ASSERT(!std::numeric_limits<TIntType>::is_signed,
- StringToUnsignedTraits_IntType_must_be_unsigned);
+ static_assert(!std::numeric_limits<TIntType>::is_signed,
+ "StringToUnsignedTraits IntType must be unsigned");
return super::TypeCheck();
}
static bool IsNegativeOverflow(TLongType value) { return false; }

Powered by Google App Engine
This is Rietveld 408576698