🐛 fix bug in move constructor

This commit is contained in:
Niels Lohmann 2021-01-03 20:06:32 +01:00
parent ec0b1798bc
commit 294fa343d5
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
3 changed files with 57 additions and 5 deletions

View File

@ -1873,9 +1873,9 @@ class basic_json
{ {
m_value.array = create<array_t>(cnt, val); m_value.array = create<array_t>(cnt, val);
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
for (auto& entry : *m_value.array) for (auto& element : *m_value.array)
{ {
entry.m_parent = this; element.m_parent = this;
} }
#endif #endif
assert_invariant(); assert_invariant();
@ -2196,6 +2196,32 @@ class basic_json
other.m_type = value_t::null; other.m_type = value_t::null;
other.m_value = {}; 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(); assert_invariant();
} }

View File

@ -18509,9 +18509,9 @@ class basic_json
{ {
m_value.array = create<array_t>(cnt, val); m_value.array = create<array_t>(cnt, val);
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
for (auto& entry : *m_value.array) for (auto& element : *m_value.array)
{ {
entry.m_parent = this; element.m_parent = this;
} }
#endif #endif
assert_invariant(); assert_invariant();
@ -18832,6 +18832,32 @@ class basic_json
other.m_type = value_t::null; other.m_type = value_t::null;
other.m_value = {}; 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(); assert_invariant();
} }

View File

@ -1280,7 +1280,7 @@ TEST_CASE("JSON patch")
std::ifstream f(filename); std::ifstream f(filename);
json suite = json::parse(f); json suite = json::parse(f);
for (const auto test : suite) for (const auto& test : suite)
{ {
INFO_WITH_TEMP(test.value("comment", "")); INFO_WITH_TEMP(test.value("comment", ""));