Skip to content

Commit

Permalink
Merge pull request #2925 from nlohmann/issue2924
Browse files Browse the repository at this point in the history
Guard GCC pragmas
  • Loading branch information
nlohmann authored Aug 12, 2021
2 parents 57d31d1 + e20f3f9 commit 910fabf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/nlohmann/detail/conversions/to_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,8 +1066,10 @@ char* to_chars(char* first, const char* last, FloatType value)
*first++ = '-';
}

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (value == 0) // +-0
{
*first++ = '0';
Expand All @@ -1076,7 +1078,9 @@ char* to_chars(char* first, const char* last, FloatType value)
*first++ = '0';
return first;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);

Expand Down
4 changes: 4 additions & 0 deletions include/nlohmann/detail/output/binary_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,8 +1525,10 @@ class binary_writer

void write_compact_float(const number_float_t n, detail::input_format_t format)
{
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) &&
static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
Expand All @@ -1543,7 +1545,9 @@ class binary_writer
: get_msgpack_float_prefix(n));
write_number(n);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}

public:
Expand Down
4 changes: 4 additions & 0 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6278,8 +6278,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
{
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
const auto lhs_type = lhs.type();
const auto rhs_type = rhs.type();

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

return false;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}

/*!
Expand Down
12 changes: 12 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14826,8 +14826,10 @@ class binary_writer

void write_compact_float(const number_float_t n, detail::input_format_t format)
{
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) &&
static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
Expand All @@ -14844,7 +14846,9 @@ class binary_writer
: get_msgpack_float_prefix(n));
write_number(n);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}

public:
Expand Down Expand Up @@ -15985,8 +15989,10 @@ char* to_chars(char* first, const char* last, FloatType value)
*first++ = '-';
}

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (value == 0) // +-0
{
*first++ = '0';
Expand All @@ -15995,7 +16001,9 @@ char* to_chars(char* first, const char* last, FloatType value)
*first++ = '0';
return first;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);

Expand Down Expand Up @@ -23370,8 +23378,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
{
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
const auto lhs_type = lhs.type();
const auto rhs_type = rhs.type();

Expand Down Expand Up @@ -23436,7 +23446,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}

return false;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}

/*!
Expand Down

0 comments on commit 910fabf

Please sign in to comment.