🚨 fixed some compiler warnings

This commit is contained in:
Niels Lohmann 2018-08-16 18:20:30 +02:00
parent d5b21b051c
commit 07494e06d7
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
7 changed files with 43 additions and 43 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -146,7 +146,7 @@ class parser
template <typename SAX>
bool sax_parse(SAX* sax, const bool strict = true)
{
(void)detail::is_sax_static_asserts<SAX, BasicJsonType>{};
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
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;
}

View file

@ -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 <typename SAX>
bool sax_parse(SAX* sax, const bool strict = true)
{
// (void)detail::is_sax_static_asserts<SAX, BasicJsonType>{};
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
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;
}

View file

@ -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<std::nullptr_t>();

View file

@ -35,45 +35,45 @@ using nlohmann::json;
#include <iostream>
#include <valarray>
struct SaxEventLogger
struct SaxEventLogger : public nlohmann::json_sax<json>
{
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()");
}