-
-
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
Unexpected behaviour of is_null - Part II #1167
Comments
For const json objects, operator[] has an undefined semantics if the given key is not present, see https://nlohmann.github.io/json/classnlohmann_1_1basic__json_ab2318780e5ae692039e816b6ac32c91e.html#ab2318780e5ae692039e816b6ac32c91e |
More details:
|
For my purposes, it was sufficient to simply remove the |
Ok, thanks for checking back! |
This is very unexpected behaviour. |
Where is the unexpected behavior here? |
When you have a non-const JSON value and use operator[] to access a non-existing key, a value is default-constructed at that key. This is the same behavior as |
The following code produces a core dump with this error message:
Assertion `m_value.object->find(key) != m_value.object->end()' failed
This is because the check inserts
{"key3", null}
into the object.I'm not sure whether this behaviour is intentionally, it might at least become a pitfall for some, so I wanted to bring this to your attention.
The text was updated successfully, but these errors were encountered: