mirror of
https://github.com/nlohmann/json.git
synced 2026-08-21 16:43:17 +00:00
Take the descent flag as an argument rather than testing it
MSVC reports the test of a constant as C4127 ("conditional expression is
constant"), which the Windows builds treat as an error: may_descend is
false for operator<, so the operand short-circuits the whole condition.
Passing it to compare_descent_exhausted() puts the test where the value
is an ordinary parameter, and leaves the call sites with no condition of
their own.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1190,15 +1190,22 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
compare_depth_guard& operator=(compare_depth_guard&&) = delete;
|
||||
};
|
||||
|
||||
/// @brief whether a comparison must stop descending and finish iteratively
|
||||
static bool compare_descent_exhausted() noexcept
|
||||
/*!
|
||||
@brief whether a comparison must stop descending and finish iteratively
|
||||
|
||||
@a may_descend says whether the operator descends at all; it is constant at
|
||||
every call site, and is passed rather than tested by the caller so that the
|
||||
test does not become a constant condition there, which MSVC reports (C4127).
|
||||
*/
|
||||
static bool compare_descent_exhausted(bool may_descend) noexcept
|
||||
{
|
||||
#ifdef JSON_NO_THREAD_LOCAL
|
||||
// without a counter of its own per thread, the descent cannot be
|
||||
// bounded without racing another one, so none is made
|
||||
static_cast<void>(may_descend);
|
||||
return true;
|
||||
#else
|
||||
return compare_depth() >= compare_depth_limit();
|
||||
return !may_descend || compare_depth() >= compare_depth_limit();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4240,7 +4247,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
{ \
|
||||
case value_t::array: \
|
||||
{ \
|
||||
if (JSON_HEDLEY_UNLIKELY(!(may_descend) || compare_descent_exhausted())) \
|
||||
if (JSON_HEDLEY_UNLIKELY(compare_descent_exhausted(may_descend))) \
|
||||
{ \
|
||||
return (deep_result); \
|
||||
} \
|
||||
@@ -4250,7 +4257,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
\
|
||||
case value_t::object: \
|
||||
{ \
|
||||
if (JSON_HEDLEY_UNLIKELY(!(may_descend) || compare_descent_exhausted())) \
|
||||
if (JSON_HEDLEY_UNLIKELY(compare_descent_exhausted(may_descend))) \
|
||||
{ \
|
||||
return (deep_result); \
|
||||
} \
|
||||
|
||||
@@ -22544,15 +22544,22 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
compare_depth_guard& operator=(compare_depth_guard&&) = delete;
|
||||
};
|
||||
|
||||
/// @brief whether a comparison must stop descending and finish iteratively
|
||||
static bool compare_descent_exhausted() noexcept
|
||||
/*!
|
||||
@brief whether a comparison must stop descending and finish iteratively
|
||||
|
||||
@a may_descend says whether the operator descends at all; it is constant at
|
||||
every call site, and is passed rather than tested by the caller so that the
|
||||
test does not become a constant condition there, which MSVC reports (C4127).
|
||||
*/
|
||||
static bool compare_descent_exhausted(bool may_descend) noexcept
|
||||
{
|
||||
#ifdef JSON_NO_THREAD_LOCAL
|
||||
// without a counter of its own per thread, the descent cannot be
|
||||
// bounded without racing another one, so none is made
|
||||
static_cast<void>(may_descend);
|
||||
return true;
|
||||
#else
|
||||
return compare_depth() >= compare_depth_limit();
|
||||
return !may_descend || compare_depth() >= compare_depth_limit();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -25594,7 +25601,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
{ \
|
||||
case value_t::array: \
|
||||
{ \
|
||||
if (JSON_HEDLEY_UNLIKELY(!(may_descend) || compare_descent_exhausted())) \
|
||||
if (JSON_HEDLEY_UNLIKELY(compare_descent_exhausted(may_descend))) \
|
||||
{ \
|
||||
return (deep_result); \
|
||||
} \
|
||||
@@ -25604,7 +25611,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
\
|
||||
case value_t::object: \
|
||||
{ \
|
||||
if (JSON_HEDLEY_UNLIKELY(!(may_descend) || compare_descent_exhausted())) \
|
||||
if (JSON_HEDLEY_UNLIKELY(compare_descent_exhausted(may_descend))) \
|
||||
{ \
|
||||
return (deep_result); \
|
||||
} \
|
||||
|
||||
Reference in New Issue
Block a user