Skip to content

Commit 5db5dd5

Browse files
authored
Merge pull request Tencent#1057 from chwarr/paren-minmax
Guard against min/max being macros in a cross-compiler way
2 parents 4bb4926 + e4c0ecf commit 5db5dd5

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

include/rapidjson/document.h

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ RAPIDJSON_DIAG_PUSH
2929
#ifdef _MSC_VER
3030
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
3131
RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
32-
#ifdef _MINWINDEF_ // see: http://stackoverflow.com/questions/22744262/cant-call-stdmax-because-minwindef-h-defines-max
33-
#ifndef NOMINMAX
34-
#pragma push_macro("min")
35-
#pragma push_macro("max")
36-
#undef min
37-
#undef max
38-
#endif
39-
#endif
4032
#endif
4133

4234
#ifdef __clang__
@@ -1018,14 +1010,14 @@ class GenericValue {
10181010
uint64_t u = GetUint64();
10191011
volatile double d = static_cast<double>(u);
10201012
return (d >= 0.0)
1021-
&& (d < static_cast<double>(std::numeric_limits<uint64_t>::max()))
1013+
&& (d < static_cast<double>((std::numeric_limits<uint64_t>::max)()))
10221014
&& (u == static_cast<uint64_t>(d));
10231015
}
10241016
if (IsInt64()) {
10251017
int64_t i = GetInt64();
10261018
volatile double d = static_cast<double>(i);
1027-
return (d >= static_cast<double>(std::numeric_limits<int64_t>::min()))
1028-
&& (d < static_cast<double>(std::numeric_limits<int64_t>::max()))
1019+
return (d >= static_cast<double>((std::numeric_limits<int64_t>::min)()))
1020+
&& (d < static_cast<double>((std::numeric_limits<int64_t>::max)()))
10291021
&& (i == static_cast<int64_t>(d));
10301022
}
10311023
return true; // double, int, uint are always lossless
@@ -1042,8 +1034,8 @@ class GenericValue {
10421034
bool IsLosslessFloat() const {
10431035
if (!IsNumber()) return false;
10441036
double a = GetDouble();
1045-
if (a < static_cast<double>(-std::numeric_limits<float>::max())
1046-
|| a > static_cast<double>(std::numeric_limits<float>::max()))
1037+
if (a < static_cast<double>(-(std::numeric_limits<float>::max)())
1038+
|| a > static_cast<double>((std::numeric_limits<float>::max)()))
10471039
return false;
10481040
double b = static_cast<double>(static_cast<float>(a));
10491041
return a >= b && a <= b; // Prevent -Wfloat-equal
@@ -2616,12 +2608,6 @@ class GenericObject {
26162608
};
26172609

26182610
RAPIDJSON_NAMESPACE_END
2619-
#ifdef _MINWINDEF_ // see: http://stackoverflow.com/questions/22744262/cant-call-stdmax-because-minwindef-h-defines-max
2620-
#ifndef NOMINMAX
2621-
#pragma pop_macro("min")
2622-
#pragma pop_macro("max")
2623-
#endif
2624-
#endif
26252611
RAPIDJSON_DIAG_POP
26262612

26272613
#endif // RAPIDJSON_DOCUMENT_H_

test/unittest/itoatest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ template <typename T>
7070
static void Verify(void(*f)(T, char*), char* (*g)(T, char*)) {
7171
// Boundary cases
7272
VerifyValue<T>(0, f, g);
73-
VerifyValue<T>(std::numeric_limits<T>::min(), f, g);
74-
VerifyValue<T>(std::numeric_limits<T>::max(), f, g);
73+
VerifyValue<T>((std::numeric_limits<T>::min)(), f, g);
74+
VerifyValue<T>((std::numeric_limits<T>::max)(), f, g);
7575

7676
// 2^n - 1, 2^n, 10^n - 1, 10^n until overflow
7777
for (int power = 2; power <= 10; power += 8) {

test/unittest/readertest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ TEST(Reader, ParseNumber_NormalPrecisionError) {
415415
uint64_t bias1 = e.ToBias();
416416
uint64_t bias2 = a.ToBias();
417417
double ulp = static_cast<double>(bias1 >= bias2 ? bias1 - bias2 : bias2 - bias1);
418-
ulpMax = std::max(ulpMax, ulp);
418+
ulpMax = (std::max)(ulpMax, ulp);
419419
ulpSum += ulp;
420420
}
421421
printf("ULP Average = %g, Max = %g \n", ulpSum / count, ulpMax);

test/unittest/strtodtest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ TEST(Strtod, CheckApproximationCase) {
9191
}
9292

9393
// Remove common power of two factor from all three scaled values
94-
int common_Exp2 = std::min(dS_Exp2, std::min(bS_Exp2, hS_Exp2));
94+
int common_Exp2 = (std::min)(dS_Exp2, (std::min)(bS_Exp2, hS_Exp2));
9595
dS_Exp2 -= common_Exp2;
9696
bS_Exp2 -= common_Exp2;
9797
hS_Exp2 -= common_Exp2;

0 commit comments

Comments
 (0)