-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Program crashes with ordered_json, but works fine with json #4279
Comments
Update: I have verified that the crash also happens when I use json.hpp from the latest release (version 3.11.3). |
You can't keep references into the
|
Thank you gregmarr, it does work this way. I didn't know of this limitation. Does the documentation mention this? If so, please excuse me. |
I don't think there is a section in iterator/pointer/reference invalidation. It is mentioned in the code at https://github.com/nlohmann/json/blob/develop/include/nlohmann/json.hpp#L768 and was the cause of #2962 fixed by #2963 There is a "todo" section here:
|
Thanks @gregmarr. I marked this as a documentation issue. |
Description
The same program (code in case 1) produces the expected result using regular nlohmann::json, but crashes using nlohmann::ordered_json. A simple variant of this program (code in case 2) produces the expected result using json, but a different result with ordered_json.
Reproduction steps
Consider this input json file ("test.json"):
The 2 small programs listed into "Minimal code example" will work fine and produce the expected results when using my_json = nlohmann::json. However, if we change the type to nlohmann::ordered_json, the first program will crash and the second program will not add new_field as expected.
Expected vs. actual results
Expected result for case 1:
Expected result for case 2:
Minimal code example
Error messages
Compiler and operating system
Windows 10, Microsoft Visual Studio Professional 2019 Version 16.11.24
Library version
Github at commit 7efe875
Validation
develop
branch is used.The text was updated successfully, but these errors were encountered: