Skip to content
Discussion options

You must be logged in to vote

I would treat this as likely a false positive unless Coverity gives a concrete path where the stored type tag and the accessed union member can really diverge.

nlohmann::json intentionally uses a tagged-union style representation. The important invariant is that the active member in m_value is determined by m_type — for example, object values use m_value.object, arrays use m_value.array, strings use m_value.string, and so on. Destruction/copy/move paths switch on the stored value_t and then access the corresponding union member.

That pattern is valid when the tag invariant is preserved, but it is also a common source of static-analysis warnings because analyzers may not be able to prove t…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@randy-xiang
Comment options

@nlohmann
Comment options

Answer selected by randy-xiang
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants