Closed
Description
When update()
is used to insert new elements into an nlohmann::json
, the parent pointers inside the newly inserted elements don't seem to be properly set.
What is the issue you have?
When parent pointers are not set correctly, an assert goes off when check_invariants()
is later called on the object. This only happens when JSON_DIAGNOSTICS is enabled.
This might be related to #2926. Although as far as I can see, this has nothing to do with serialization.
Please describe the steps to reproduce the issue.
Live example: https://godbolt.org/z/Ms5hP35fW
Can you provide a small but working code example?
Same as the live code:
#include <nlohmann/json.hpp>
int main () {
nlohmann::json root = nlohmann::json::array();
nlohmann::json lower = nlohmann::json::object();
{
nlohmann::json lowest = nlohmann::json::object();
lowest["one"] = 1;
lower.update(lowest);
}
root.push_back(lower);
}
What is the expected behavior?
Parent pointers should be properly set. As a result no assert should go off.
And what is the actual behavior instead?
Parent pointers are not set, assertion goes off as a result.
Which compiler and operating system are you using?
Tested with:
- g++ 10.3 on Gentoo 2.6
- g++ 11.1 on Compiler Explorer (godbolt.org)
Which version of the library did you use?
- latest release version 3.10.2
- other release - please state the version: ___
- the
develop
branch