Guard against min/max being macros in document.h
Sometimes, particularly when Microsoft's windows.h is included, min/max are defined as macros, interfering with use of std::numeric_limits::min() and the like. To guard against this, the function name is wrapped in an extra set of parenthesis, which inhibits function-style macro expansion.
This commit is contained in:
parent
1e46091009
commit
6e38649ec6
@ -29,14 +29,6 @@ RAPIDJSON_DIAG_PUSH
|
|||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
||||||
RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
|
RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
|
||||||
#ifdef _MINWINDEF_ // see: http://stackoverflow.com/questions/22744262/cant-call-stdmax-because-minwindef-h-defines-max
|
|
||||||
#ifndef NOMINMAX
|
|
||||||
#pragma push_macro("min")
|
|
||||||
#pragma push_macro("max")
|
|
||||||
#undef min
|
|
||||||
#undef max
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
@ -1018,14 +1010,14 @@ public:
|
|||||||
uint64_t u = GetUint64();
|
uint64_t u = GetUint64();
|
||||||
volatile double d = static_cast<double>(u);
|
volatile double d = static_cast<double>(u);
|
||||||
return (d >= 0.0)
|
return (d >= 0.0)
|
||||||
&& (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
|
&& (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
|
||||||
&& (u == static_cast<uint64_t>(d));
|
&& (u == static_cast<uint64_t>(d));
|
||||||
}
|
}
|
||||||
if (IsInt64()) {
|
if (IsInt64()) {
|
||||||
int64_t i = GetInt64();
|
int64_t i = GetInt64();
|
||||||
volatile double d = static_cast<double>(i);
|
volatile double d = static_cast<double>(i);
|
||||||
return (d >= static_cast<double>(std::numeric_limits<int64_t>::min()))
|
return (d >= static_cast<double>((std::numeric_limits<int64_t>::min)()))
|
||||||
&& (d < static_cast<double>(std::numeric_limits<int64_t>::max()))
|
&& (d < static_cast<double>((std::numeric_limits<int64_t>::max)()))
|
||||||
&& (i == static_cast<int64_t>(d));
|
&& (i == static_cast<int64_t>(d));
|
||||||
}
|
}
|
||||||
return true; // double, int, uint are always lossless
|
return true; // double, int, uint are always lossless
|
||||||
@ -1042,8 +1034,8 @@ public:
|
|||||||
bool IsLosslessFloat() const {
|
bool IsLosslessFloat() const {
|
||||||
if (!IsNumber()) return false;
|
if (!IsNumber()) return false;
|
||||||
double a = GetDouble();
|
double a = GetDouble();
|
||||||
if (a < static_cast<double>(-std::numeric_limits<float>::max())
|
if (a < static_cast<double>(-(std::numeric_limits<float>::max)())
|
||||||
|| a > static_cast<double>(std::numeric_limits<float>::max()))
|
|| a > static_cast<double>((std::numeric_limits<float>::max)()))
|
||||||
return false;
|
return false;
|
||||||
double b = static_cast<double>(static_cast<float>(a));
|
double b = static_cast<double>(static_cast<float>(a));
|
||||||
return a >= b && a <= b; // Prevent -Wfloat-equal
|
return a >= b && a <= b; // Prevent -Wfloat-equal
|
||||||
@ -2616,12 +2608,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
RAPIDJSON_NAMESPACE_END
|
RAPIDJSON_NAMESPACE_END
|
||||||
#ifdef _MINWINDEF_ // see: http://stackoverflow.com/questions/22744262/cant-call-stdmax-because-minwindef-h-defines-max
|
|
||||||
#ifndef NOMINMAX
|
|
||||||
#pragma pop_macro("min")
|
|
||||||
#pragma pop_macro("max")
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
RAPIDJSON_DIAG_POP
|
RAPIDJSON_DIAG_POP
|
||||||
|
|
||||||
#endif // RAPIDJSON_DOCUMENT_H_
|
#endif // RAPIDJSON_DOCUMENT_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user