diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index b60122cc..5a66a860 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1035,9 +1035,12 @@ class basic_json { stack.push_back(std::move(it.second)); } + + current_item.m_value.object->clear(); } - // current_item is destroyed here + // it's now safe that current_item get destructed + // since it doesn't have any children } switch (t) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index d2d85b3d..8acb1cc0 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15578,9 +15578,12 @@ class basic_json { stack.push_back(std::move(it.second)); } + + current_item.m_value.object->clear(); } - // current_item is destroyed here + // it's now safe that current_item get destructed + // since it doesn't have any children } switch (t)