Fix MSVC C4127 warning-as-error in is_exactly_representable_as_float

MSVC's /W4 flags 'if (float_digits >= int_digits)' as C4127 (conditional
expression is constant), since both operands are constexpr int for any
single template instantiation. This CI job builds with warnings-as-errors,
failing the build.

Apply the same MSVC-only pragma push/disable(4127)/pop pattern already
used elsewhere in the codebase (see json.hpp's set_parents() workaround)
rather than if constexpr, since this file must stay C++11-compatible.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-07-10 07:37:26 +02:00
parent 48face7a20
commit 8557b661ab
2 changed files with 14 additions and 0 deletions
+7
View File
@@ -40,10 +40,17 @@ inline bool is_exactly_representable_as_float(typename BasicJsonType::number_int
constexpr int float_digits = std::numeric_limits<number_float_t>::digits;
constexpr int int_digits = std::numeric_limits<number_integer_t>::digits;
#ifdef JSON_HEDLEY_MSVC_VERSION
#pragma warning(push )
#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr
#endif
if (float_digits >= int_digits)
{
return true;
}
#ifdef JSON_HEDLEY_MSVC_VERSION
#pragma warning( pop )
#endif
// For values outside float's exact range, they don't round-trip
// The safe way to check: compute the max magnitude that round-trips
+7
View File
@@ -6708,10 +6708,17 @@ inline bool is_exactly_representable_as_float(typename BasicJsonType::number_int
constexpr int float_digits = std::numeric_limits<number_float_t>::digits;
constexpr int int_digits = std::numeric_limits<number_integer_t>::digits;
#ifdef JSON_HEDLEY_MSVC_VERSION
#pragma warning(push )
#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr
#endif
if (float_digits >= int_digits)
{
return true;
}
#ifdef JSON_HEDLEY_MSVC_VERSION
#pragma warning( pop )
#endif
// For values outside float's exact range, they don't round-trip
// The safe way to check: compute the max magnitude that round-trips