diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 2fc497bae..a8ae98957 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1873,9 +1873,9 @@ class basic_json { m_value.array = create(cnt, val); #if JSON_DIAGNOSTICS - for (auto& entry : *m_value.array) + for (auto& element : *m_value.array) { - entry.m_parent = this; + element.m_parent = this; } #endif assert_invariant(); @@ -2196,6 +2196,32 @@ class basic_json other.m_type = value_t::null; other.m_value = {}; +#if JSON_DIAGNOSTICS + switch (m_type) + { + case value_t::array: + { + for (auto& element : *m_value.array) + { + element.m_parent = this; + } + break; + } + + case value_t::object: + { + for (auto& element : *m_value.object) + { + element.second.m_parent = this; + } + break; + } + + default: + break; + } +#endif + assert_invariant(); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f9bb662d1..210f33141 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -18509,9 +18509,9 @@ class basic_json { m_value.array = create(cnt, val); #if JSON_DIAGNOSTICS - for (auto& entry : *m_value.array) + for (auto& element : *m_value.array) { - entry.m_parent = this; + element.m_parent = this; } #endif assert_invariant(); @@ -18832,6 +18832,32 @@ class basic_json other.m_type = value_t::null; other.m_value = {}; +#if JSON_DIAGNOSTICS + switch (m_type) + { + case value_t::array: + { + for (auto& element : *m_value.array) + { + element.m_parent = this; + } + break; + } + + case value_t::object: + { + for (auto& element : *m_value.object) + { + element.second.m_parent = this; + } + break; + } + + default: + break; + } +#endif + assert_invariant(); } diff --git a/test/src/unit-json_patch.cpp b/test/src/unit-json_patch.cpp index cf11b5603..53570113b 100644 --- a/test/src/unit-json_patch.cpp +++ b/test/src/unit-json_patch.cpp @@ -1280,7 +1280,7 @@ TEST_CASE("JSON patch") std::ifstream f(filename); json suite = json::parse(f); - for (const auto test : suite) + for (const auto& test : suite) { INFO_WITH_TEMP(test.value("comment", ""));