From 883fb29583f3f46cf6527fd8641f5fc4de30a0b7 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 5 Sep 2026 21:01:30 +0200 Subject: [PATCH 1/2] Route hand-rolled diagnostic pragmas through Hedley Several places in the library hand-roll compiler diagnostic suppression with raw `#pragma`/`#ifdef __GNUC__`/`#ifdef __clang__` guards instead of using the Hedley primitives already bundled and used elsewhere (JSON_HEDLEY_DIAGNOSTIC_PUSH/POP, JSON_HEDLEY_PRAGMA, ...). Converted six of the seven listed push/pop pairs to use those primitives instead of raw `#pragma GCC diagnostic`/`#pragma clang diagnostic` text: - include/nlohmann/json.hpp (~3770, ~3863): -Wfloat-equal - include/nlohmann/detail/conversions/to_chars.hpp (~1078): -Wfloat-equal - include/nlohmann/detail/output/binary_writer.hpp (~1844): -Wfloat-equal - include/nlohmann/detail/iterators/iteration_proxy.hpp (~211): -Wmismatched-tags - include/nlohmann/detail/exceptions.hpp (~36): -Wweak-vtables iteration_proxy.hpp did not previously include macro_scope.hpp itself (it only compiled because some other header included earlier in json.hpp happened to pull macro_scope.hpp in first); it now includes it directly like the other detail headers that use Hedley macros, so it is self-contained. Each push/pop pair now uses JSON_HEDLEY_DIAGNOSTIC_PUSH/POP unconditionally (a no-op on compilers that don't need it) and wraps the actual `#pragma ... diagnostic ignored` text in JSON_HEDLEY_PRAGMA so it goes through Hedley's _Pragma()-based emission instead of a raw #pragma line, while keeping the original `#ifdef __GNUC__` / `#if defined(__clang__)` guard around the ignored-pragma itself. Deviation from the issue's suggested transformation: the issue's example replaces the `#ifdef __GNUC__` guard with `#if JSON_HEDLEY_HAS_WARNING("-Wfloat-equal")`. JSON_HEDLEY_HAS_WARNING is implemented purely via Clang's `__has_warning` builtin and evaluates to 0 on real GCC (`#define JSON_HEDLEY_HAS_WARNING(warning) (0)` when `__has_warning` is not defined), so adopting it verbatim would silently stop suppressing -Wfloat-equal on GCC -- a real regression, not just a style change. The existing `#ifdef __GNUC__` / `#if defined(__clang__)` guards were kept for the ignored-pragma to stay behavior-preserving, and only the push/pop/pragma-emission mechanism was routed through Hedley. Two of the seven locations from the issue (the -Wignored-attributes push at the very top of json.hpp and its matching pop after `#include `) were intentionally left unconverted: - The push, at the very top of json.hpp, runs before `detail/macro_scope.hpp` (and therefore hedley.hpp) has been included anywhere in the translation unit, so JSON_HEDLEY_DIAGNOSTIC_PUSH is not yet defined at that point. - The pop runs after `macro_unscope.hpp`, which -- via hedley_undef.hpp -- has already #undef'd every JSON_HEDLEY_* macro (by design, see #5408) precisely so they don't leak to users, so JSON_HEDLEY_DIAGNOSTIC_POP is no longer defined by the time the pop is reached either. Making this one pair work would require either hoisting the ~2000 line vendored hedley.hpp to the very top of the amalgamated single header (a much bigger structural change to single_include than a pure mechanism swap) or special-casing this one pop ahead of the general macro cleanup. Both are riskier than the mechanical, behavior-preserving change requested, so this pair was left as-is. ## Validation - Compiled include/nlohmann/json.hpp and single_include/nlohmann/json.hpp with `-Wall -Wextra -Wfloat-equal -Wmismatched-tags -Wweak-vtables` (clang, which self-identifies as __GNUC__ too): no warnings, same as before the change. - Compiled and ran tests/src/unit-to_chars.cpp, unit-conversions.cpp, unit-iterators1.cpp, unit-iterators2.cpp, and unit-class_parser.cpp against the fixed include/: all pass. - Compiled unit-msgpack.cpp, unit-bjdata.cpp, and unit-ubjson.cpp (which exercise binary_writer.hpp's write_compact_float extensively): all compile cleanly; the vast majority of assertions pass (the only failures are pre-existing environment issues unrelated to this change -- missing generated test-data files, not code correctness). - Ran `make amalgamate`; the single_include diff is limited to exactly the lines touched in include/, with no unrelated reordering. - No real (non-Apple) GCC was available in this environment to test directly; the `_Pragma("GCC diagnostic ...")` text emitted by JSON_HEDLEY_PRAGMA is byte-identical to the prior `#pragma GCC diagnostic ...` text, and the `#ifdef __GNUC__` guard is unchanged, so GCC's behavior is expected to be identical. CI covers the GCC matrix. This PR is stacked on top of #5475 (issue-5408-hedley-undef-leak) since both touch the same files; only the last commit here is new. Fixes #5409. Signed-off-by: Niels Lohmann --- .../nlohmann/detail/conversions/to_chars.hpp | 8 ++- include/nlohmann/detail/exceptions.hpp | 8 ++- .../detail/iterators/iteration_proxy.hpp | 11 ++-- .../nlohmann/detail/output/binary_writer.hpp | 8 ++- include/nlohmann/json.hpp | 16 +++--- single_include/nlohmann/json.hpp | 52 ++++++++----------- 6 files changed, 41 insertions(+), 62 deletions(-) diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index 70fb9b933e9..1b3d0c704a6 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -1074,9 +1074,9 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '-'; } + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (value == 0) // +-0 { @@ -1086,9 +1086,7 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '0'; return first; } -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP JSON_ASSERT(last - first >= std::numeric_limits::max_digits10); diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index cb87bb93ef6..d93d8d71e63 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -32,9 +32,9 @@ // functions to. As a result, we suppress this warning here to avoid client // code stumbling over this. See https://github.com/nlohmann/json/issues/4087 // for a discussion. +JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wweak-vtables" + JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wweak-vtables") #endif NLOHMANN_JSON_NAMESPACE_BEGIN @@ -286,6 +286,4 @@ class other_error : public exception } // namespace detail NLOHMANN_JSON_NAMESPACE_END -#if defined(__clang__) - #pragma clang diagnostic pop -#endif +JSON_HEDLEY_DIAGNOSTIC_POP diff --git a/include/nlohmann/detail/iterators/iteration_proxy.hpp b/include/nlohmann/detail/iterators/iteration_proxy.hpp index 99246d12033..5bae6c7ede6 100644 --- a/include/nlohmann/detail/iterators/iteration_proxy.hpp +++ b/include/nlohmann/detail/iterators/iteration_proxy.hpp @@ -18,6 +18,7 @@ #endif #include +#include #include #include #include @@ -206,10 +207,10 @@ NLOHMANN_JSON_NAMESPACE_END namespace std { +// Fix: https://github.com/nlohmann/json/issues/1401 +JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) - // Fix: https://github.com/nlohmann/json/issues/1401 - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wmismatched-tags" + JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wmismatched-tags") #endif template class tuple_size<::nlohmann::detail::iteration_proxy_value> // NOLINT(cert-dcl58-cpp) @@ -223,9 +224,7 @@ class tuple_element> get(std::declval < ::nlohmann::detail::iteration_proxy_value> ())); }; -#if defined(__clang__) - #pragma clang diagnostic pop -#endif +JSON_HEDLEY_DIAGNOSTIC_POP } // namespace std diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index b8e9efa45ef..7875c63b2c7 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1849,9 +1849,9 @@ class binary_writer void write_compact_float(const number_float_t n, detail::input_format_t format) { + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (!std::isfinite(n) || ((static_cast(n) >= static_cast(std::numeric_limits::lowest()) && static_cast(n) <= static_cast((std::numeric_limits::max)()) && @@ -1869,9 +1869,7 @@ class binary_writer : get_msgpack_float_prefix(n)); write_number(n); } -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP } public: diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 6f9876478c2..40a1ead497c 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3770,15 +3770,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(const_reference rhs) const noexcept { + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif const_reference lhs = *this; JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP } /// @brief comparison: equal @@ -3863,14 +3861,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP } /// @brief comparison: equal diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 68691769c4f..d547257efb3 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4944,9 +4944,9 @@ NLOHMANN_JSON_NAMESPACE_END // functions to. As a result, we suppress this warning here to avoid client // code stumbling over this. See https://github.com/nlohmann/json/issues/4087 // for a discussion. +JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wweak-vtables" + JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wweak-vtables") #endif NLOHMANN_JSON_NAMESPACE_BEGIN @@ -5198,9 +5198,7 @@ class other_error : public exception } // namespace detail NLOHMANN_JSON_NAMESPACE_END -#if defined(__clang__) - #pragma clang diagnostic pop -#endif +JSON_HEDLEY_DIAGNOSTIC_POP // #include @@ -5975,6 +5973,8 @@ NLOHMANN_JSON_NAMESPACE_END // #include +// #include + // #include // #include @@ -6204,10 +6204,10 @@ NLOHMANN_JSON_NAMESPACE_END namespace std { +// Fix: https://github.com/nlohmann/json/issues/1401 +JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) - // Fix: https://github.com/nlohmann/json/issues/1401 - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wmismatched-tags" + JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wmismatched-tags") #endif template class tuple_size<::nlohmann::detail::iteration_proxy_value> // NOLINT(cert-dcl58-cpp) @@ -6221,9 +6221,7 @@ class tuple_element> get(std::declval < ::nlohmann::detail::iteration_proxy_value> ())); }; -#if defined(__clang__) - #pragma clang diagnostic pop -#endif +JSON_HEDLEY_DIAGNOSTIC_POP } // namespace std @@ -18981,9 +18979,9 @@ class binary_writer void write_compact_float(const number_float_t n, detail::input_format_t format) { + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (!std::isfinite(n) || ((static_cast(n) >= static_cast(std::numeric_limits::lowest()) && static_cast(n) <= static_cast((std::numeric_limits::max)()) && @@ -19001,9 +18999,7 @@ class binary_writer : get_msgpack_float_prefix(n)); write_number(n); } -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP } public: @@ -20176,9 +20172,9 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '-'; } + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (value == 0) // +-0 { @@ -20188,9 +20184,7 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '0'; return first; } -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP JSON_ASSERT(last - first >= std::numeric_limits::max_digits10); @@ -25322,15 +25316,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(const_reference rhs) const noexcept { + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif const_reference lhs = *this; JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP } /// @brief comparison: equal @@ -25415,14 +25407,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { + JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif JSON_IMPLEMENT_OPERATOR( ==, true, false, false) -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif + JSON_HEDLEY_DIAGNOSTIC_POP } /// @brief comparison: equal From f07f5f66ba64264613f433b2cbf5b537868d641c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 8 Sep 2026 19:55:54 +0200 Subject: [PATCH 2/2] Guard JSON_HEDLEY_DIAGNOSTIC_PUSH/POP with the same compiler check as the pragma they bracket Addresses review feedback from @gregmarr on PR #5485: the push/pop calls were unconditional, so compilers other than the one the ignored-pragma targets (e.g. MSVC, or GCC where the pair only applies under __clang__) now did a needless push/pop with nothing suppressed in between. Move the existing #ifdef __GNUC__ / #if defined(__clang__) guard to also cover the push/pop, restoring the original zero-overhead behavior on other compilers while still emitting the pragma itself through Hedley. Signed-off-by: Niels Lohmann --- .../nlohmann/detail/conversions/to_chars.hpp | 4 ++- include/nlohmann/detail/exceptions.hpp | 6 ++-- .../detail/iterators/iteration_proxy.hpp | 6 ++-- .../nlohmann/detail/output/binary_writer.hpp | 4 ++- include/nlohmann/json.hpp | 8 ++++-- single_include/nlohmann/json.hpp | 28 +++++++++++++------ 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index 1b3d0c704a6..c0945ab9e03 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -1074,8 +1074,8 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '-'; } - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (value == 0) // +-0 @@ -1086,7 +1086,9 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '0'; return first; } +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif JSON_ASSERT(last - first >= std::numeric_limits::max_digits10); diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index d93d8d71e63..3e5b45101f0 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -32,8 +32,8 @@ // functions to. As a result, we suppress this warning here to avoid client // code stumbling over this. See https://github.com/nlohmann/json/issues/4087 // for a discussion. -JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wweak-vtables") #endif @@ -286,4 +286,6 @@ class other_error : public exception } // namespace detail NLOHMANN_JSON_NAMESPACE_END -JSON_HEDLEY_DIAGNOSTIC_POP +#if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_POP +#endif diff --git a/include/nlohmann/detail/iterators/iteration_proxy.hpp b/include/nlohmann/detail/iterators/iteration_proxy.hpp index 5bae6c7ede6..c8aa50dd2de 100644 --- a/include/nlohmann/detail/iterators/iteration_proxy.hpp +++ b/include/nlohmann/detail/iterators/iteration_proxy.hpp @@ -208,8 +208,8 @@ namespace std { // Fix: https://github.com/nlohmann/json/issues/1401 -JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wmismatched-tags") #endif template @@ -224,7 +224,9 @@ class tuple_element> get(std::declval < ::nlohmann::detail::iteration_proxy_value> ())); }; -JSON_HEDLEY_DIAGNOSTIC_POP +#if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_POP +#endif } // namespace std diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 7875c63b2c7..496c733d122 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1849,8 +1849,8 @@ class binary_writer void write_compact_float(const number_float_t n, detail::input_format_t format) { - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (!std::isfinite(n) || ((static_cast(n) >= static_cast(std::numeric_limits::lowest()) && @@ -1869,7 +1869,9 @@ class binary_writer : get_msgpack_float_prefix(n)); write_number(n); } +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif } public: diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 40a1ead497c..feafd9e20dc 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3770,13 +3770,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(const_reference rhs) const noexcept { - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif const_reference lhs = *this; JSON_IMPLEMENT_OPERATOR( ==, true, false, false) +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif } /// @brief comparison: equal @@ -3861,12 +3863,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif JSON_IMPLEMENT_OPERATOR( ==, true, false, false) +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif } /// @brief comparison: equal diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index d547257efb3..605bf836499 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4944,8 +4944,8 @@ NLOHMANN_JSON_NAMESPACE_END // functions to. As a result, we suppress this warning here to avoid client // code stumbling over this. See https://github.com/nlohmann/json/issues/4087 // for a discussion. -JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wweak-vtables") #endif @@ -5198,7 +5198,9 @@ class other_error : public exception } // namespace detail NLOHMANN_JSON_NAMESPACE_END -JSON_HEDLEY_DIAGNOSTIC_POP +#if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_POP +#endif // #include @@ -6205,8 +6207,8 @@ namespace std { // Fix: https://github.com/nlohmann/json/issues/1401 -JSON_HEDLEY_DIAGNOSTIC_PUSH #if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wmismatched-tags") #endif template @@ -6221,7 +6223,9 @@ class tuple_element> get(std::declval < ::nlohmann::detail::iteration_proxy_value> ())); }; -JSON_HEDLEY_DIAGNOSTIC_POP +#if defined(__clang__) + JSON_HEDLEY_DIAGNOSTIC_POP +#endif } // namespace std @@ -18979,8 +18983,8 @@ class binary_writer void write_compact_float(const number_float_t n, detail::input_format_t format) { - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (!std::isfinite(n) || ((static_cast(n) >= static_cast(std::numeric_limits::lowest()) && @@ -18999,7 +19003,9 @@ class binary_writer : get_msgpack_float_prefix(n)); write_number(n); } +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif } public: @@ -20172,8 +20178,8 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '-'; } - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif if (value == 0) // +-0 @@ -20184,7 +20190,9 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '0'; return first; } +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif JSON_ASSERT(last - first >= std::numeric_limits::max_digits10); @@ -25316,13 +25324,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(const_reference rhs) const noexcept { - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif const_reference lhs = *this; JSON_IMPLEMENT_OPERATOR( ==, true, false, false) +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif } /// @brief comparison: equal @@ -25407,12 +25417,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { - JSON_HEDLEY_DIAGNOSTIC_PUSH #ifdef __GNUC__ + JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif JSON_IMPLEMENT_OPERATOR( ==, true, false, false) +#ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP +#endif } /// @brief comparison: equal