diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 27c34edb..19aae087 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -1560,7 +1560,7 @@ class binary_reader } else { - if (JSON_UNLIKELY(not sax->start_array(-1))) + if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1)))) { return false; } @@ -1630,7 +1630,7 @@ class binary_reader } else { - if (JSON_UNLIKELY(not sax->start_object(-1))) + if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1)))) { return false; } diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index fe1cf7c5..2a2e6011 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -190,7 +190,7 @@ class json_sax_dom_parser { ref_stack.push_back(handle_value(BasicJsonType::value_t::object)); - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len))); @@ -216,7 +216,7 @@ class json_sax_dom_parser { ref_stack.push_back(handle_value(BasicJsonType::value_t::array)); - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len))); @@ -373,7 +373,7 @@ class json_sax_dom_callback_parser // check object limit if (ref_stack.back()) { - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len))); @@ -446,7 +446,7 @@ class json_sax_dom_callback_parser // check array limit if (ref_stack.back()) { - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len))); @@ -649,7 +649,7 @@ class json_sax_acceptor return true; } - bool start_object(std::size_t = -1) + bool start_object(std::size_t = std::size_t(-1)) { return true; } @@ -664,7 +664,7 @@ class json_sax_acceptor return true; } - bool start_array(std::size_t = -1) + bool start_array(std::size_t = std::size_t(-1)) { return true; } diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index cfb8b65e..70d92a26 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -146,7 +146,7 @@ class parser template bool sax_parse(SAX* sax, const bool strict = true) { - (void)detail::is_sax_static_asserts{}; + (void)detail::is_sax_static_asserts {}; const bool result = sax_parse_internal(sax); // strict mode: next byte must be EOF @@ -179,7 +179,7 @@ class parser { case token_type::begin_object: { - if (JSON_UNLIKELY(not sax->start_object(-1))) + if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1)))) { return false; } @@ -227,7 +227,7 @@ class parser case token_type::begin_array: { - if (JSON_UNLIKELY(not sax->start_array(-1))) + if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1)))) { return false; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2e73d98f..dacdcfbf 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3966,7 +3966,7 @@ class json_sax_dom_parser { ref_stack.push_back(handle_value(BasicJsonType::value_t::object)); - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len))); @@ -3992,7 +3992,7 @@ class json_sax_dom_parser { ref_stack.push_back(handle_value(BasicJsonType::value_t::array)); - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len))); @@ -4149,7 +4149,7 @@ class json_sax_dom_callback_parser // check object limit if (ref_stack.back()) { - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len))); @@ -4222,7 +4222,7 @@ class json_sax_dom_callback_parser // check array limit if (ref_stack.back()) { - if (JSON_UNLIKELY(len != -1 and len > ref_stack.back()->max_size())) + if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len))); @@ -4425,7 +4425,7 @@ class json_sax_acceptor return true; } - bool start_object(std::size_t = -1) + bool start_object(std::size_t = std::size_t(-1)) { return true; } @@ -4440,7 +4440,7 @@ class json_sax_acceptor return true; } - bool start_array(std::size_t = -1) + bool start_array(std::size_t = std::size_t(-1)) { return true; } @@ -4595,7 +4595,7 @@ class parser template bool sax_parse(SAX* sax, const bool strict = true) { - // (void)detail::is_sax_static_asserts{}; + (void)detail::is_sax_static_asserts {}; const bool result = sax_parse_internal(sax); // strict mode: next byte must be EOF @@ -4628,7 +4628,7 @@ class parser { case token_type::begin_object: { - if (JSON_UNLIKELY(not sax->start_object(-1))) + if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1)))) { return false; } @@ -4676,7 +4676,7 @@ class parser case token_type::begin_array: { - if (JSON_UNLIKELY(not sax->start_array(-1))) + if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1)))) { return false; } @@ -7515,7 +7515,7 @@ class binary_reader } else { - if (JSON_UNLIKELY(not sax->start_array(-1))) + if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1)))) { return false; } @@ -7585,7 +7585,7 @@ class binary_reader } else { - if (JSON_UNLIKELY(not sax->start_object(-1))) + if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1)))) { return false; } diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 787897ca..bf6332ff 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -435,7 +435,7 @@ TEST_CASE("value conversion") SECTION("get null (explicit)") { - std::nullptr_t n; + std::nullptr_t n = nullptr; json j(n); auto n2 = j.get(); diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index e122628e..af58a0fe 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -35,45 +35,45 @@ using nlohmann::json; #include #include -struct SaxEventLogger +struct SaxEventLogger : public nlohmann::json_sax { - bool null() + bool null() override { events.push_back("null()"); return true; } - bool boolean(bool val) + bool boolean(bool val) override { events.push_back(val ? "boolean(true)" : "boolean(false)"); return true; } - bool number_integer(json::number_integer_t val) + bool number_integer(json::number_integer_t val) override { events.push_back("number_integer(" + std::to_string(val) + ")"); return true; } - bool number_unsigned(json::number_unsigned_t val) + bool number_unsigned(json::number_unsigned_t val) override { events.push_back("number_unsigned(" + std::to_string(val) + ")"); return true; } - bool number_float(json::number_float_t, const std::string& s) + bool number_float(json::number_float_t, const std::string& s) override { events.push_back("number_float(" + s + ")"); return true; } - bool string(std::string& val) + bool string(std::string& val) override { events.push_back("string(" + val + ")"); return true; } - bool start_object(std::size_t elements) + bool start_object(std::size_t elements) override { if (elements == std::size_t(-1)) { @@ -86,19 +86,19 @@ struct SaxEventLogger return true; } - bool key(std::string& val) + bool key(std::string& val) override { events.push_back("key(" + val + ")"); return true; } - bool end_object() + bool end_object() override { events.push_back("end_object()"); return true; } - bool start_array(std::size_t elements) + bool start_array(std::size_t elements) override { if (elements == std::size_t(-1)) { @@ -111,13 +111,13 @@ struct SaxEventLogger return true; } - bool end_array() + bool end_array() override { events.push_back("end_array()"); return true; } - bool parse_error(std::size_t position, const std::string&, const json::exception&) + bool parse_error(std::size_t position, const std::string&, const json::exception&) override { events.push_back("parse_error(" + std::to_string(position) + ")"); return false; @@ -128,9 +128,9 @@ struct SaxEventLogger struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger { - bool start_object(std::size_t elements) + bool start_object(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_object()"); } @@ -144,7 +144,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger struct SaxEventLoggerExitAfterKey : public SaxEventLogger { - bool key(std::string& val) + bool key(std::string& val) override { events.push_back("key(" + val + ")"); return false; @@ -153,9 +153,9 @@ struct SaxEventLoggerExitAfterKey : public SaxEventLogger struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger { - bool start_array(std::size_t elements) + bool start_array(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_array()"); } diff --git a/test/src/unit-inspection.cpp b/test/src/unit-inspection.cpp index e50c7338..4c03cf96 100644 --- a/test/src/unit-inspection.cpp +++ b/test/src/unit-inspection.cpp @@ -317,8 +317,8 @@ TEST_CASE("object inspection") SECTION("round trips") { for (const auto& s : - {"3.141592653589793", "1000000000000000010E5" - }) + {"3.141592653589793", "1000000000000000010E5" + }) { json j1 = json::parse(s); std::string s1 = j1.dump();