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

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: fixes 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
« no previous file with comments | « util/posix/symbolic_constants_posix.cc ('k') | util/stdlib/strlcpy_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0c16c0386cc31143eaee706661c825c061834c34 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
-// 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.
+// CONSTEXPR_STATIC_ASSERT will be a normal static_assert if the C++ library 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; }
« no previous file with comments | « util/posix/symbolic_constants_posix.cc ('k') | util/stdlib/strlcpy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698