diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 31ca64539b..f4d582f504 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1213,11 +1213,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept : json_base_class_t(std::forward(other)), - m_data(std::move(other.m_data)) + // check that passed value is valid (has to be done before moving) + m_data(std::move((other.assert_invariant(false), other.m_data))) { - // check that passed value is valid - other.assert_invariant(false); - // invalidate payload other.m_data.m_type = value_t::null; other.m_data.m_value = {}; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 82138b02f5..546ea18d29 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20516,11 +20516,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept : json_base_class_t(std::forward(other)), - m_data(std::move(other.m_data)) + // check that passed value is valid (has to be done before moving) + m_data(std::move((other.assert_invariant(false), other.m_data))) { - // check that passed value is valid - other.assert_invariant(false); - // invalidate payload other.m_data.m_type = value_t::null; other.m_data.m_value = {};