Skip to content

Commit

Permalink
Add more suppressions on float comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
Finkman committed Aug 4, 2021
1 parent 095aae1 commit 353d597
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/nlohmann/detail/conversions/to_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<FloatType>::max_digits10);

Expand Down
3 changes: 3 additions & 0 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -6342,6 +6344,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}

return false;
#pragma GCC diagnostic pop
}

/*!
Expand Down
6 changes: 6 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15984,6 +15984,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';
Expand All @@ -15992,6 +15994,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<FloatType>::max_digits10);

Expand Down Expand Up @@ -23366,6 +23369,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();

Expand Down Expand Up @@ -23430,6 +23435,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}

return false;
#pragma GCC diagnostic pop
}

/*!
Expand Down

0 comments on commit 353d597

Please sign in to comment.