Skip to content

Commit

Permalink
check -> const_check to avoid a conflict with AssertMacros.h (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 12, 2016
1 parent 4133e50 commit 8631694
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
18 changes: 9 additions & 9 deletions fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ inline DummyInt _isnan(...) { return DummyInt(); }
// A helper function to suppress bogus "conditional expression is constant"
// warnings.
template <typename T>
inline T check(T value) { return value; }
inline T const_check(T value) { return value; }
}
} // namespace fmt

Expand All @@ -328,8 +328,8 @@ class numeric_limits<fmt::internal::DummyInt> :
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<double>(x));
Expand All @@ -339,8 +339,8 @@ class numeric_limits<fmt::internal::DummyInt> :
template <typename T>
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<double>(x)) != 0;
Expand All @@ -349,7 +349,7 @@ class numeric_limits<fmt::internal::DummyInt> :
// 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;
Expand Down Expand Up @@ -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<int>(value);
else
long_long_value = value;
Expand All @@ -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<unsigned>(value);
else
ulong_long_value = value;
Expand Down Expand Up @@ -1861,7 +1861,7 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
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);
Expand Down
4 changes: 2 additions & 2 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 5 additions & 4 deletions test/printf-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<U>::max();
using fmt::internal::check;
if (check(max <= static_cast<unsigned>(std::numeric_limits<int>::max()))) {
using std::numeric_limits;
fmt::ULongLong max = numeric_limits<U>::max();
using fmt::internal::const_check;
if (const_check(max <= static_cast<unsigned>(numeric_limits<int>::max()))) {
signed_value = static_cast<int>(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);
unsigned_value = static_cast<unsigned>(value);
}
Expand Down

0 comments on commit 8631694

Please sign in to comment.