mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 12:10:32 +00:00
Remove four cppcheck accessForwarded suppressions in the move constructor
basic_json(basic_json&&) built its base subobject with std::forward<json_base_class_t>(other), so cppcheck saw the whole of other as forwarded and flagged every subsequent access to it as accessForwarded, three of them still marked "TODO check". Only the base subobject is actually moved from; cast explicitly to the base type instead, the way ordered_map already does, so cppcheck can tell the two are unrelated. Behavior is unchanged: for a non-reference T, std::forward<T>(x) is defined as static_cast<T&&>(x). Part of #5724 Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1942,15 +1942,15 @@ 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(std::forward<json_base_class_t>(other)),
|
||||
m_data(std::move(other.m_data)) // cppcheck-suppress[accessForwarded] TODO check
|
||||
: json_base_class_t(std::move(static_cast<json_base_class_t&>(other))),
|
||||
m_data(std::move(other.m_data))
|
||||
#if JSON_DIAGNOSTIC_POSITIONS
|
||||
, start_position(other.start_position) // cppcheck-suppress[accessForwarded] TODO check
|
||||
, end_position(other.end_position) // cppcheck-suppress[accessForwarded] TODO check
|
||||
, start_position(other.start_position)
|
||||
, end_position(other.end_position)
|
||||
#endif
|
||||
{
|
||||
// check that the passed value is valid
|
||||
other.assert_invariant(false); // cppcheck-suppress[accessForwarded]
|
||||
other.assert_invariant(false);
|
||||
|
||||
// invalidate payload
|
||||
other.m_data.m_type = value_t::null;
|
||||
|
||||
@@ -28023,15 +28023,15 @@ 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(std::forward<json_base_class_t>(other)),
|
||||
m_data(std::move(other.m_data)) // cppcheck-suppress[accessForwarded] TODO check
|
||||
: json_base_class_t(std::move(static_cast<json_base_class_t&>(other))),
|
||||
m_data(std::move(other.m_data))
|
||||
#if JSON_DIAGNOSTIC_POSITIONS
|
||||
, start_position(other.start_position) // cppcheck-suppress[accessForwarded] TODO check
|
||||
, end_position(other.end_position) // cppcheck-suppress[accessForwarded] TODO check
|
||||
, start_position(other.start_position)
|
||||
, end_position(other.end_position)
|
||||
#endif
|
||||
{
|
||||
// check that the passed value is valid
|
||||
other.assert_invariant(false); // cppcheck-suppress[accessForwarded]
|
||||
other.assert_invariant(false);
|
||||
|
||||
// invalidate payload
|
||||
other.m_data.m_type = value_t::null;
|
||||
|
||||
Reference in New Issue
Block a user