check -> const_check to avoid a conflict with AssertMacros.h (#350)

This commit is contained in:
Victor Zverovich 2016-07-12 06:40:23 -07:00
parent 4133e501f3
commit 8631694021
3 changed files with 16 additions and 15 deletions

View File

@ -309,7 +309,7 @@ inline DummyInt _isnan(...) { return DummyInt(); }
// A helper function to suppress bogus "conditional expression is constant" // A helper function to suppress bogus "conditional expression is constant"
// warnings. // warnings.
template <typename T> template <typename T>
inline T check(T value) { return value; } inline T const_check(T value) { return value; }
} }
} // namespace fmt } // namespace fmt
@ -328,8 +328,8 @@ class numeric_limits<fmt::internal::DummyInt> :
using namespace fmt::internal; using namespace fmt::internal;
// The resolution "priority" is: // The resolution "priority" is:
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf // isinf macro > std::isinf > ::isinf > fmt::internal::isinf
if (check(sizeof(isinf(x)) == sizeof(bool) || if (const_check(sizeof(isinf(x)) == sizeof(bool) ||
sizeof(isinf(x)) == sizeof(int))) { sizeof(isinf(x)) == sizeof(int))) {
return isinf(x) != 0; return isinf(x) != 0;
} }
return !_finite(static_cast<double>(x)); return !_finite(static_cast<double>(x));
@ -339,8 +339,8 @@ class numeric_limits<fmt::internal::DummyInt> :
template <typename T> template <typename T>
static bool isnotanumber(T x) { static bool isnotanumber(T x) {
using namespace fmt::internal; using namespace fmt::internal;
if (check(sizeof(isnan(x)) == sizeof(bool) || if (const_check(sizeof(isnan(x)) == sizeof(bool) ||
sizeof(isnan(x)) == sizeof(int))) { sizeof(isnan(x)) == sizeof(int))) {
return isnan(x) != 0; return isnan(x) != 0;
} }
return _isnan(static_cast<double>(x)) != 0; return _isnan(static_cast<double>(x)) != 0;
@ -349,7 +349,7 @@ class numeric_limits<fmt::internal::DummyInt> :
// Portable version of signbit. // Portable version of signbit.
static bool isnegative(double x) { static bool isnegative(double x) {
using namespace fmt::internal; using namespace fmt::internal;
if (check(sizeof(signbit(x)) == sizeof(int))) if (const_check(sizeof(signbit(x)) == sizeof(int)))
return signbit(x) != 0; return signbit(x) != 0;
if (x < 0) return true; if (x < 0) return true;
if (!isnotanumber(x)) return false; if (!isnotanumber(x)) return false;
@ -1200,7 +1200,7 @@ class MakeValue : public Arg {
MakeValue(long value) { MakeValue(long value) {
// To minimize the number of types we need to deal with, long is // To minimize the number of types we need to deal with, long is
// translated either to int or to long long depending on its size. // translated either to int or to long long depending on its size.
if (check(sizeof(long) == sizeof(int))) if (const_check(sizeof(long) == sizeof(int)))
int_value = static_cast<int>(value); int_value = static_cast<int>(value);
else else
long_long_value = value; long_long_value = value;
@ -1210,7 +1210,7 @@ class MakeValue : public Arg {
} }
MakeValue(unsigned long value) { MakeValue(unsigned long value) {
if (check(sizeof(unsigned long) == sizeof(unsigned))) if (const_check(sizeof(unsigned long) == sizeof(unsigned)))
uint_value = static_cast<unsigned>(value); uint_value = static_cast<unsigned>(value);
else else
ulong_long_value = value; ulong_long_value = value;
@ -1861,7 +1861,7 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
out += spec_.width_ - CHAR_WIDTH; out += spec_.width_ - CHAR_WIDTH;
} else if (spec_.align_ == ALIGN_CENTER) { } else if (spec_.align_ == ALIGN_CENTER) {
out = writer_.fill_padding(out, spec_.width_, out = writer_.fill_padding(out, spec_.width_,
internal::check(CHAR_WIDTH), fill); internal::const_check(CHAR_WIDTH), fill);
} else { } else {
std::uninitialized_fill_n(out + CHAR_WIDTH, std::uninitialized_fill_n(out + CHAR_WIDTH,
spec_.width_ - CHAR_WIDTH, fill); spec_.width_ - CHAR_WIDTH, fill);

View File

@ -933,7 +933,7 @@ TEST(FormatterTest, RuntimeWidth) {
FormatError, "number is too big"); FormatError, "number is too big");
EXPECT_THROW_MSG(format("{0:{1}}", 0, -1l), EXPECT_THROW_MSG(format("{0:{1}}", 0, -1l),
FormatError, "negative width"); FormatError, "negative width");
if (fmt::internal::check(sizeof(long) > sizeof(int))) { if (fmt::internal::const_check(sizeof(long) > sizeof(int))) {
long value = INT_MAX; long value = INT_MAX;
EXPECT_THROW_MSG(format("{0:{1}}", 0, (value + 1)), EXPECT_THROW_MSG(format("{0:{1}}", 0, (value + 1)),
FormatError, "number is too big"); FormatError, "number is too big");
@ -1052,7 +1052,7 @@ TEST(FormatterTest, RuntimePrecision) {
FormatError, "number is too big"); FormatError, "number is too big");
EXPECT_THROW_MSG(format("{0:.{1}}", 0, -1l), EXPECT_THROW_MSG(format("{0:.{1}}", 0, -1l),
FormatError, "negative precision"); FormatError, "negative precision");
if (fmt::internal::check(sizeof(long) > sizeof(int))) { if (fmt::internal::const_check(sizeof(long) > sizeof(int))) {
long value = INT_MAX; long value = INT_MAX;
EXPECT_THROW_MSG(format("{0:.{1}}", 0, (value + 1)), EXPECT_THROW_MSG(format("{0:.{1}}", 0, (value + 1)),
FormatError, "number is too big"); FormatError, "number is too big");

View File

@ -296,12 +296,13 @@ void TestLength(const char *length_spec, U value) {
fmt::LongLong signed_value = 0; fmt::LongLong signed_value = 0;
fmt::ULongLong unsigned_value = 0; fmt::ULongLong unsigned_value = 0;
// Apply integer promotion to the argument. // Apply integer promotion to the argument.
fmt::ULongLong max = std::numeric_limits<U>::max(); using std::numeric_limits;
using fmt::internal::check; fmt::ULongLong max = numeric_limits<U>::max();
if (check(max <= static_cast<unsigned>(std::numeric_limits<int>::max()))) { using fmt::internal::const_check;
if (const_check(max <= static_cast<unsigned>(numeric_limits<int>::max()))) {
signed_value = static_cast<int>(value); signed_value = static_cast<int>(value);
unsigned_value = static_cast<unsigned>(value); unsigned_value = static_cast<unsigned>(value);
} else if (check(max <= std::numeric_limits<unsigned>::max())) { } else if (const_check(max <= numeric_limits<unsigned>::max())) {
signed_value = static_cast<unsigned>(value); signed_value = static_cast<unsigned>(value);
unsigned_value = static_cast<unsigned>(value); unsigned_value = static_cast<unsigned>(value);
} }