diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8290a30b4..b11cf1bb0 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15990,7 +15990,7 @@ class binary_reader } const bool negative = second >= 0xC0; - std::int64_t value = static_cast(negative ? (second & 0x3F) : second); + auto value = static_cast(negative ? (second & 0x3F) : second); std::int64_t offset = 0; int extra_bytes = 0; @@ -21194,6 +21194,21 @@ class binary_writer return to_char_type(std::is_same::value ? 0x8E : 0x8F); } + /// @return the type marker for a FloatType value in @a format (CBOR, MessagePack, or BON8) + template + static CharType get_compact_float_prefix(const detail::input_format_t format) + { + if (format == detail::input_format_t::cbor) + { + return get_cbor_float_prefix(FloatType{}); + } + if (format == detail::input_format_t::bon8) + { + return get_bon8_float_prefix(); + } + return get_msgpack_float_prefix(FloatType{}); + } + //////////// // UBJSON // //////////// @@ -21971,6 +21986,7 @@ class binary_writer */ static void check_bon8_utf8(const string_t& s, const BasicJsonType& context) { + static_cast(context); // only used when exceptions are enabled const auto* data = reinterpret_cast(s.data()); for (std::size_t i = 0; i < s.size();) { @@ -22086,15 +22102,15 @@ class binary_writer JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif - if (n == -1.0) + if (n == static_cast(-1)) { oa.write_character(to_char_type(0xFB)); } - else if (n == 0.0 && !std::signbit(n)) + else if (n == static_cast(0) && !std::signbit(n)) { oa.write_character(to_char_type(0xFC)); } - else if (n == 1.0) + else if (n == static_cast(1)) { oa.write_character(to_char_type(0xFD)); } @@ -22245,20 +22261,12 @@ class binary_writer static_cast(n) <= static_cast((std::numeric_limits::max)()) && static_cast(static_cast(n)) == static_cast(n)))) { - oa.write_character(format == detail::input_format_t::cbor - ? get_cbor_float_prefix(static_cast(n)) - : format == detail::input_format_t::bon8 - ? get_bon8_float_prefix() - : get_msgpack_float_prefix(static_cast(n))); + oa.write_character(get_compact_float_prefix(format)); write_number(static_cast(n)); } else { - oa.write_character(format == detail::input_format_t::cbor - ? get_cbor_float_prefix(n) - : format == detail::input_format_t::bon8 - ? get_bon8_float_prefix() - : get_msgpack_float_prefix(n)); + oa.write_character(get_compact_float_prefix(format)); write_number(n); } #ifdef __GNUC__