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:
Niels Lohmann
2026-09-30 10:36:41 +02:00
parent f5e4b9b8cf
commit ffd3a3722b
2 changed files with 10 additions and 10 deletions
+5 -5
View File
@@ -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;
+5 -5
View File
@@ -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;