diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index e20763c4..9f2a53a5 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -35,6 +35,7 @@ class binary_reader { using number_integer_t = typename BasicJsonType::number_integer_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; using string_t = typename BasicJsonType::string_t; using json_sax_t = json_sax; @@ -423,19 +424,21 @@ class binary_reader val = (mant == 0) ? std::numeric_limits::infinity() : std::numeric_limits::quiet_NaN(); } - return sax->number_float((half & 0x8000) != 0 ? -val : val, ""); + return sax->number_float((half & 0x8000) != 0 + ? static_cast(-val) + : static_cast(val), ""); } case 0xFA: // Single-Precision Float (four-byte IEEE 754) { float number; - return get_number(number) and sax->number_float(static_cast(number), ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 0xFB: // Double-Precision Float (eight-byte IEEE 754) { double number; - return get_number(number) and sax->number_float(number, ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } default: // anything else (0xFF is handled inside the other types) @@ -676,13 +679,13 @@ class binary_reader case 0xCA: // float 32 { float number; - return get_number(number) and sax->number_float(static_cast(number), ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 0xCB: // float 64 { double number; - return get_number(number) and sax->number_float(number, ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 0xCC: // uint 8 @@ -1464,13 +1467,13 @@ class binary_reader case 'd': { float number; - return get_number(number) and sax->number_float(static_cast(number), ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 'D': { double number; - return get_number(number) and sax->number_float(number, ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 'C': // char @@ -1664,7 +1667,7 @@ class binary_reader std::string get_token_string() const { char cr[3]; - snprintf(cr, 3, "%.2X", current); + snprintf(cr, 3, "%.2hhX", static_cast(current)); return std::string{cr}; } diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 3fb79068..facd6871 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -1173,7 +1173,7 @@ scan_number_done: { // escape control characters char cs[9]; - snprintf(cs, 9, "", c); + snprintf(cs, 9, "", c); result += cs; } else diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b5035f19..4cf28888 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3165,7 +3165,7 @@ scan_number_done: { // escape control characters char cs[9]; - snprintf(cs, 9, "", c); + snprintf(cs, 9, "", c); result += cs; } else @@ -5670,6 +5670,7 @@ class binary_reader { using number_integer_t = typename BasicJsonType::number_integer_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; using string_t = typename BasicJsonType::string_t; using json_sax_t = json_sax; @@ -6058,19 +6059,21 @@ class binary_reader val = (mant == 0) ? std::numeric_limits::infinity() : std::numeric_limits::quiet_NaN(); } - return sax->number_float((half & 0x8000) != 0 ? -val : val, ""); + return sax->number_float((half & 0x8000) != 0 + ? static_cast(-val) + : static_cast(val), ""); } case 0xFA: // Single-Precision Float (four-byte IEEE 754) { float number; - return get_number(number) and sax->number_float(static_cast(number), ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 0xFB: // Double-Precision Float (eight-byte IEEE 754) { double number; - return get_number(number) and sax->number_float(number, ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } default: // anything else (0xFF is handled inside the other types) @@ -6311,13 +6314,13 @@ class binary_reader case 0xCA: // float 32 { float number; - return get_number(number) and sax->number_float(static_cast(number), ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 0xCB: // float 64 { double number; - return get_number(number) and sax->number_float(number, ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 0xCC: // uint 8 @@ -7099,13 +7102,13 @@ class binary_reader case 'd': { float number; - return get_number(number) and sax->number_float(static_cast(number), ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 'D': { double number; - return get_number(number) and sax->number_float(number, ""); + return get_number(number) and sax->number_float(static_cast(number), ""); } case 'C': // char @@ -7299,7 +7302,7 @@ class binary_reader std::string get_token_string() const { char cr[3]; - snprintf(cr, 3, "%.2X", current); + snprintf(cr, 3, "%.2hhX", static_cast(current)); return std::string{cr}; } diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 061a2458..df9a6c18 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -40,14 +40,6 @@ using nlohmann::json; #include #include -namespace -{ -template -void map_type_conversion_checks() -{ -} -} - TEST_CASE("value conversion") { SECTION("get an object (explicit)") diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index 24c4195d..51a209f1 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -1191,7 +1191,7 @@ TEST_CASE("nst's JSONTestSuite (2)") { CAPTURE(filename); std::ifstream f(filename); - CHECK_THROWS_AS(json::parse(f), json::parse_error); + CHECK_THROWS_AS(json::parse(f), json::parse_error&); std::ifstream f2(filename); CHECK(not json::accept(f2)); } @@ -1306,7 +1306,7 @@ TEST_CASE("nst's JSONTestSuite (2)") { CAPTURE(filename); std::ifstream f(filename); - CHECK_THROWS_AS(json::parse(f), json::exception); // could be parse_error or out_of_range + CHECK_THROWS_AS(json::parse(f), json::exception&); // could be parse_error or out_of_range std::ifstream f2(filename); CHECK(not json::accept(f2)); }