check -> const_check to avoid a conflict with AssertMacros.h (#350)
This commit is contained in:
parent
4133e501f3
commit
8631694021
18
fmt/format.h
18
fmt/format.h
@ -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
|
||||
|
||||
@ -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));
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user