diff --git a/fmt/format.h b/fmt/format.h index 9a6426e6..49bbdeff 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -309,7 +309,7 @@ inline DummyInt _isnan(...) { return DummyInt(); } // A helper function to suppress bogus "conditional expression is constant" // warnings. template -inline T check(T value) { return value; } +inline T const_check(T value) { return value; } } } // namespace fmt @@ -328,8 +328,8 @@ class numeric_limits : using namespace fmt::internal; // The resolution "priority" is: // isinf macro > std::isinf > ::isinf > fmt::internal::isinf - if (check(sizeof(isinf(x)) == sizeof(bool) || - sizeof(isinf(x)) == sizeof(int))) { + if (const_check(sizeof(isinf(x)) == sizeof(bool) || + sizeof(isinf(x)) == sizeof(int))) { return isinf(x) != 0; } return !_finite(static_cast(x)); @@ -339,8 +339,8 @@ class numeric_limits : template static bool isnotanumber(T x) { using namespace fmt::internal; - if (check(sizeof(isnan(x)) == sizeof(bool) || - sizeof(isnan(x)) == sizeof(int))) { + if (const_check(sizeof(isnan(x)) == sizeof(bool) || + sizeof(isnan(x)) == sizeof(int))) { return isnan(x) != 0; } return _isnan(static_cast(x)) != 0; @@ -349,7 +349,7 @@ class numeric_limits : // Portable version of signbit. static bool isnegative(double x) { using namespace fmt::internal; - if (check(sizeof(signbit(x)) == sizeof(int))) + if (const_check(sizeof(signbit(x)) == sizeof(int))) return signbit(x) != 0; if (x < 0) return true; if (!isnotanumber(x)) return false; @@ -1200,7 +1200,7 @@ class MakeValue : public Arg { MakeValue(long value) { // 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. - if (check(sizeof(long) == sizeof(int))) + if (const_check(sizeof(long) == sizeof(int))) int_value = static_cast(value); else long_long_value = value; @@ -1210,7 +1210,7 @@ class MakeValue : public Arg { } MakeValue(unsigned long value) { - if (check(sizeof(unsigned long) == sizeof(unsigned))) + if (const_check(sizeof(unsigned long) == sizeof(unsigned))) uint_value = static_cast(value); else ulong_long_value = value; @@ -1861,7 +1861,7 @@ class ArgFormatterBase : public ArgVisitor { out += spec_.width_ - CHAR_WIDTH; } else if (spec_.align_ == ALIGN_CENTER) { out = writer_.fill_padding(out, spec_.width_, - internal::check(CHAR_WIDTH), fill); + internal::const_check(CHAR_WIDTH), fill); } else { std::uninitialized_fill_n(out + CHAR_WIDTH, spec_.width_ - CHAR_WIDTH, fill); diff --git a/test/format-test.cc b/test/format-test.cc index 89994c76..da9e57a8 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -933,7 +933,7 @@ TEST(FormatterTest, RuntimeWidth) { FormatError, "number is too big"); EXPECT_THROW_MSG(format("{0:{1}}", 0, -1l), FormatError, "negative width"); - if (fmt::internal::check(sizeof(long) > sizeof(int))) { + if (fmt::internal::const_check(sizeof(long) > sizeof(int))) { long value = INT_MAX; EXPECT_THROW_MSG(format("{0:{1}}", 0, (value + 1)), FormatError, "number is too big"); @@ -1052,7 +1052,7 @@ TEST(FormatterTest, RuntimePrecision) { FormatError, "number is too big"); EXPECT_THROW_MSG(format("{0:.{1}}", 0, -1l), FormatError, "negative precision"); - if (fmt::internal::check(sizeof(long) > sizeof(int))) { + if (fmt::internal::const_check(sizeof(long) > sizeof(int))) { long value = INT_MAX; EXPECT_THROW_MSG(format("{0:.{1}}", 0, (value + 1)), FormatError, "number is too big"); diff --git a/test/printf-test.cc b/test/printf-test.cc index 06d5f383..2e3f19c7 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -296,12 +296,13 @@ void TestLength(const char *length_spec, U value) { fmt::LongLong signed_value = 0; fmt::ULongLong unsigned_value = 0; // Apply integer promotion to the argument. - fmt::ULongLong max = std::numeric_limits::max(); - using fmt::internal::check; - if (check(max <= static_cast(std::numeric_limits::max()))) { + using std::numeric_limits; + fmt::ULongLong max = numeric_limits::max(); + using fmt::internal::const_check; + if (const_check(max <= static_cast(numeric_limits::max()))) { signed_value = static_cast(value); unsigned_value = static_cast(value); - } else if (check(max <= std::numeric_limits::max())) { + } else if (const_check(max <= numeric_limits::max())) { signed_value = static_cast(value); unsigned_value = static_cast(value); }