diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index e904d10fa..e5c1d01f1 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -1066,6 +1066,8 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '-'; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" if (value == 0) // +-0 { *first++ = '0'; @@ -1074,6 +1076,7 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '0'; return first; } +#pragma GCC diagnostic pop JSON_ASSERT(last - first >= std::numeric_limits::max_digits10); diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 24e7c1094..8a172056b 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1524,6 +1524,8 @@ class binary_writer void write_compact_float(const number_float_t n, detail::input_format_t format) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" if (static_cast(n) >= static_cast(std::numeric_limits::lowest()) && static_cast(n) <= static_cast((std::numeric_limits::max)()) && static_cast(static_cast(n)) == static_cast(n)) @@ -1540,6 +1542,7 @@ class binary_writer : get_msgpack_float_prefix(n)); write_number(n); } +#pragma GCC diagnostic pop } public: diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index cda764262..cd8152811 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -6278,6 +6278,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" const auto lhs_type = lhs.type(); const auto rhs_type = rhs.type(); @@ -6342,6 +6344,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } return false; +#pragma GCC diagnostic pop } /*! diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index fc3d34159..6efa460ee 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -14827,6 +14827,8 @@ class binary_writer void write_compact_float(const number_float_t n, detail::input_format_t format) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" if (static_cast(n) >= static_cast(std::numeric_limits::lowest()) && static_cast(n) <= static_cast((std::numeric_limits::max)()) && static_cast(static_cast(n)) == static_cast(n)) @@ -14843,6 +14845,7 @@ class binary_writer : get_msgpack_float_prefix(n)); write_number(n); } +#pragma GCC diagnostic pop } public: @@ -15983,6 +15986,8 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '-'; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" if (value == 0) // +-0 { *first++ = '0'; @@ -15991,6 +15996,7 @@ char* to_chars(char* first, const char* last, FloatType value) *first++ = '0'; return first; } +#pragma GCC diagnostic pop JSON_ASSERT(last - first >= std::numeric_limits::max_digits10); @@ -23365,6 +23371,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" const auto lhs_type = lhs.type(); const auto rhs_type = rhs.type(); @@ -23429,6 +23437,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } return false; +#pragma GCC diagnostic pop } /*! diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index f0baec98e..d3b81d814 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -28,7 +28,6 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #include using nlohmann::json; diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index 884a1e6f1..09329ecd6 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -28,7 +28,6 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #define JSON_TESTS_PRIVATE #include diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index 7db7b4e6b..7da9c3bf5 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -28,7 +28,6 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #include using nlohmann::json; diff --git a/test/src/unit-reference_access.cpp b/test/src/unit-reference_access.cpp index 125c7ea4f..c0477d19d 100644 --- a/test/src/unit-reference_access.cpp +++ b/test/src/unit-reference_access.cpp @@ -28,7 +28,6 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #include using nlohmann::json; diff --git a/test/src/unit-regression1.cpp b/test/src/unit-regression1.cpp index 3d4a42fe1..cfb6885fd 100644 --- a/test/src/unit-regression1.cpp +++ b/test/src/unit-regression1.cpp @@ -28,7 +28,6 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") // for some reason including this after the json header leads to linker errors with VS 2017... #include diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index fa5de3179..e58ae745f 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -28,7 +28,6 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") // for some reason including this after the json header leads to linker errors with VS 2017... #include