From 5b6fd511283cc4914350de976a38596b25813c12 Mon Sep 17 00:00:00 2001 From: Sven Fink Date: Wed, 4 Aug 2021 08:34:53 +0200 Subject: [PATCH] Add more suppressions on float comparisons --- include/nlohmann/detail/conversions/to_chars.hpp | 3 +++ include/nlohmann/json.hpp | 3 +++ single_include/nlohmann/json.hpp | 6 ++++++ 3 files changed, 12 insertions(+) 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/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 21ef36b72..08c7470c2 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15993,6 +15993,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'; @@ -16001,6 +16003,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); @@ -23375,6 +23378,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(); @@ -23439,6 +23444,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } return false; +#pragma GCC diagnostic pop } /*!