From 0a8e16d87238796dd618ab815297f58fa1b67131 Mon Sep 17 00:00:00 2001 From: barcode Date: Tue, 5 Jul 2022 09:52:44 +0200 Subject: [PATCH] Adapt code to review --- docs/examples/json_base_class_t.cpp | 7 ++++--- docs/mkdocs/docs/api/basic_json/json_base_class_t.md | 2 +- include/nlohmann/json.hpp | 4 ++-- include/nlohmann/json_fwd.hpp | 2 +- tests/src/unit-custom-base-class.cpp | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/examples/json_base_class_t.cpp b/docs/examples/json_base_class_t.cpp index 6f4822ac4..d993522a7 100644 --- a/docs/examples/json_base_class_t.cpp +++ b/docs/examples/json_base_class_t.cpp @@ -54,8 +54,6 @@ void visitor_adaptor_with_metadata::do_visit(const Ptr& ptr, const Fnc& fnc) con j.at(i).do_visit(ptr / std::to_string(i), fnc); } break; - case value_t::discarded: - break; case value_t::null: case value_t::string: case value_t::boolean: @@ -63,8 +61,11 @@ void visitor_adaptor_with_metadata::do_visit(const Ptr& ptr, const Fnc& fnc) con case value_t::number_unsigned: case value_t::number_float: case value_t::binary: - default: fnc(ptr, j); + break; + case value_t::discarded: + default: + break; } } diff --git a/docs/mkdocs/docs/api/basic_json/json_base_class_t.md b/docs/mkdocs/docs/api/basic_json/json_base_class_t.md index 6da2cba81..af12f241b 100644 --- a/docs/mkdocs/docs/api/basic_json/json_base_class_t.md +++ b/docs/mkdocs/docs/api/basic_json/json_base_class_t.md @@ -21,7 +21,7 @@ The default value for `CustomBaseClass` is `void`. In this case an empty base cl #### Limitations The type `CustomBaseClass` has to be a default constructible class. -`basic_json` only supports copy/move construction/assignement if `CustomBaseClass` does so as well. +`basic_json` only supports copy/move construction/assignment if `CustomBaseClass` does so as well. ## Examples diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index bc73e1631..7beb4563c 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1204,12 +1204,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief move constructor /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept - : json_base_class_t(static_cast < json_base_class_t&& > (other)), + : json_base_class_t(std::move(other)), m_type(std::move(other.m_type)), m_value(std::move(other.m_value)) { // check that passed value is valid - other.assert_invariant(false); + other.assert_invariant(false); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) // invalidate payload other.m_type = value_t::null; diff --git a/include/nlohmann/json_fwd.hpp b/include/nlohmann/json_fwd.hpp index af3ce7a29..7d814dafa 100644 --- a/include/nlohmann/json_fwd.hpp +++ b/include/nlohmann/json_fwd.hpp @@ -46,7 +46,7 @@ template class ObjectType = template class AllocatorType = std::allocator, template class JSONSerializer = adl_serializer, - class BinaryType = std::vector, // cppcheck-suppress syntaxError + class BinaryType = std::vector, class CustomBaseClass = void> class basic_json; diff --git a/tests/src/unit-custom-base-class.cpp b/tests/src/unit-custom-base-class.cpp index dfa49f7d5..1803bd864 100644 --- a/tests/src/unit-custom-base-class.cpp +++ b/tests/src/unit-custom-base-class.cpp @@ -175,7 +175,7 @@ TEST_CASE("JSON Node Metadata") { using json = json_with_metadata>; json value; - value.metadata().reset(new int(42)); // NOLINT + value.metadata().reset(new int(42)); // NOLINT(cppcoreguidelines-owning-memory) auto moved = std::move(value); CHECK(moved.metadata() != nullptr);