From d047b3d4957c11c4b7ebd94f3e61c7d469def804 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 16 Jul 2020 14:45:39 +0200 Subject: [PATCH] :rotating_light: remove linter warning --- .../nlohmann/detail/input/input_adapters.hpp | 4 +- include/nlohmann/detail/input/json_sax.hpp | 44 +++-------------- single_include/nlohmann/json.hpp | 48 ++++--------------- 3 files changed, 16 insertions(+), 80 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 05493531e..63921ca55 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -36,7 +36,7 @@ class file_input_adapter using char_type = char; JSON_HEDLEY_NON_NULL(2) - explicit file_input_adapter(std::FILE* f) noexcept + explicit file_input_adapter(std::FILE* f) noexcept : m_file(f) {} @@ -90,7 +90,7 @@ class input_stream_adapter input_stream_adapter& operator=(input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&& rhs) = delete; - input_stream_adapter(input_stream_adapter&& rhs) : is(rhs.is), sb(rhs.sb) + input_stream_adapter(input_stream_adapter&& rhs) noexcept : is(rhs.is), sb(rhs.sb) { rhs.is = nullptr; rhs.sb = nullptr; diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index d1443d6ae..ae6a6cbe2 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -258,30 +258,14 @@ class json_sax_dom_parser return true; } + template bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const detail::exception& ex) + const Exception& ex) { errored = true; if (allow_exceptions) { - // determine the proper exception type from the id - switch ((ex.id / 100) % 100) - { - case 1: - JSON_THROW(*dynamic_cast(&ex)); - case 4: - JSON_THROW(*dynamic_cast(&ex)); - // LCOV_EXCL_START - case 2: - JSON_THROW(*dynamic_cast(&ex)); - case 3: - JSON_THROW(*dynamic_cast(&ex)); - case 5: - JSON_THROW(*dynamic_cast(&ex)); - default: - JSON_ASSERT(false); - // LCOV_EXCL_STOP - } + JSON_THROW(ex); } return false; } @@ -512,30 +496,14 @@ class json_sax_dom_callback_parser return true; } + template bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const detail::exception& ex) + const Exception& ex) { errored = true; if (allow_exceptions) { - // determine the proper exception type from the id - switch ((ex.id / 100) % 100) - { - case 1: - JSON_THROW(*dynamic_cast(&ex)); - case 4: - JSON_THROW(*dynamic_cast(&ex)); - // LCOV_EXCL_START - case 2: - JSON_THROW(*dynamic_cast(&ex)); - case 3: - JSON_THROW(*dynamic_cast(&ex)); - case 5: - JSON_THROW(*dynamic_cast(&ex)); - default: - JSON_ASSERT(false); - // LCOV_EXCL_STOP - } + JSON_THROW(ex); } return false; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 1d02cc12b..32986cb6e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4500,7 +4500,7 @@ class file_input_adapter using char_type = char; JSON_HEDLEY_NON_NULL(2) - explicit file_input_adapter(std::FILE* f) noexcept + explicit file_input_adapter(std::FILE* f) noexcept : m_file(f) {} @@ -4554,7 +4554,7 @@ class input_stream_adapter input_stream_adapter& operator=(input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&& rhs) = delete; - input_stream_adapter(input_stream_adapter&& rhs) : is(rhs.is), sb(rhs.sb) + input_stream_adapter(input_stream_adapter&& rhs) noexcept : is(rhs.is), sb(rhs.sb) { rhs.is = nullptr; rhs.sb = nullptr; @@ -5180,30 +5180,14 @@ class json_sax_dom_parser return true; } + template bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const detail::exception& ex) + const Exception& ex) { errored = true; if (allow_exceptions) { - // determine the proper exception type from the id - switch ((ex.id / 100) % 100) - { - case 1: - JSON_THROW(*dynamic_cast(&ex)); - case 4: - JSON_THROW(*dynamic_cast(&ex)); - // LCOV_EXCL_START - case 2: - JSON_THROW(*dynamic_cast(&ex)); - case 3: - JSON_THROW(*dynamic_cast(&ex)); - case 5: - JSON_THROW(*dynamic_cast(&ex)); - default: - JSON_ASSERT(false); - // LCOV_EXCL_STOP - } + JSON_THROW(ex); } return false; } @@ -5434,30 +5418,14 @@ class json_sax_dom_callback_parser return true; } + template bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, - const detail::exception& ex) + const Exception& ex) { errored = true; if (allow_exceptions) { - // determine the proper exception type from the id - switch ((ex.id / 100) % 100) - { - case 1: - JSON_THROW(*dynamic_cast(&ex)); - case 4: - JSON_THROW(*dynamic_cast(&ex)); - // LCOV_EXCL_START - case 2: - JSON_THROW(*dynamic_cast(&ex)); - case 3: - JSON_THROW(*dynamic_cast(&ex)); - case 5: - JSON_THROW(*dynamic_cast(&ex)); - default: - JSON_ASSERT(false); - // LCOV_EXCL_STOP - } + JSON_THROW(ex); } return false; }