From 8d6b3d44d6255a540c620ad4c683b4a669b6acdc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 25 Feb 2018 18:35:16 +0100 Subject: [PATCH] :ok_hand: fixed some compiler warnings --- include/nlohmann/detail/input/parser.hpp | 8 +++++--- single_include/nlohmann/json.hpp | 8 +++++--- test/src/unit-class_parser.cpp | 10 +++++----- test/src/unit-deserialization.cpp | 14 +++++++------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index 1cd6868f..67bdcd49 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -96,7 +96,9 @@ class parser /// a parse error occurred /// the byte position and the last token are reported - virtual bool parse_error(int position, const std::string& last_token) = 0; + virtual bool parse_error(std::size_t position, const std::string& last_token) = 0; + + virtual ~SAX() = default; }; using parser_callback_t = @@ -585,7 +587,7 @@ class parser { case token_type::begin_object: { - if (not sax->start_object(-1)) + if (not sax->start_object(std::size_t(-1))) { return false; } @@ -654,7 +656,7 @@ class parser case token_type::begin_array: { - if (not sax->start_array(-1)) + if (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 79581142..9c04cd9b 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3219,7 +3219,9 @@ class parser /// a parse error occurred /// the byte position and the last token are reported - virtual bool parse_error(int position, const std::string& last_token) = 0; + virtual bool parse_error(std::size_t position, const std::string& last_token) = 0; + + virtual ~SAX() = default; }; using parser_callback_t = @@ -3708,7 +3710,7 @@ class parser { case token_type::begin_object: { - if (not sax->start_object(-1)) + if (not sax->start_object(std::size_t(-1))) { return false; } @@ -3777,7 +3779,7 @@ class parser case token_type::begin_array: { - if (not sax->start_array(-1)) + if (not sax->start_array(std::size_t(-1))) { return false; } diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index 27c1ee8d..94acaaa5 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -61,7 +61,7 @@ class SaxEventLogger : public nlohmann::json::SAX return true; } - bool number_float(json::number_float_t val, const std::string& s) override + bool number_float(json::number_float_t, const std::string& s) override { events.push_back("number_float(" + s + ")"); return true; @@ -75,7 +75,7 @@ class SaxEventLogger : public nlohmann::json::SAX bool start_object(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_object()"); } @@ -100,7 +100,7 @@ class SaxEventLogger : public nlohmann::json::SAX bool start_array(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_array()"); } @@ -117,13 +117,13 @@ class SaxEventLogger : public nlohmann::json::SAX return true; } - bool binary(const std::vector& vec) override + bool binary(const std::vector&) override { events.push_back("binary()"); return true; } - bool parse_error(int position, const std::string& last_token) override + bool parse_error(std::size_t position, const std::string&) override { errored = true; events.push_back("parse_error(" + std::to_string(position) + ")"); diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index 9f0bc175..603773b9 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -60,7 +60,7 @@ struct SaxEventLogger : public nlohmann::json::SAX return true; } - bool number_float(json::number_float_t val, const std::string& s) override + bool number_float(json::number_float_t, const std::string& s) override { events.push_back("number_float(" + s + ")"); return true; @@ -74,7 +74,7 @@ struct SaxEventLogger : public nlohmann::json::SAX bool start_object(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_object()"); } @@ -99,7 +99,7 @@ struct SaxEventLogger : public nlohmann::json::SAX bool start_array(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_array()"); } @@ -116,13 +116,13 @@ struct SaxEventLogger : public nlohmann::json::SAX return true; } - bool binary(const std::vector& vec) override + bool binary(const std::vector&) override { events.push_back("binary()"); return true; } - bool parse_error(int position, const std::string& last_token) override + bool parse_error(std::size_t position, const std::string&) override { events.push_back("parse_error(" + std::to_string(position) + ")"); return false; @@ -135,7 +135,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger { bool start_object(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_object()"); } @@ -160,7 +160,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger { bool start_array(std::size_t elements) override { - if (elements == -1) + if (elements == std::size_t(-1)) { events.push_back("start_array()"); }