-
-
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
Mixing different JSON_DIAGNOSTICS settings in separately compiled units leads to core #3360
Comments
As an additional info: the code does not SEGV anymore if I get rid of the array:
|
A workaround I am using is setting JSON_DIAGNOSTICS only globally in the Makefile, still I think it should be considered a bug. |
Mixing binaries compiled with and without diagnostics is not expected to work as the latter introduces a new data member, so objects are not compatible. If you want to use diagnostics, you have to use them everywhere by defining |
What you are trying to do is a violation of the C++ "One Definition Rule" (ODR). This means that any type must have the same definition everywhere that it is used in a single program. If you violate this, then your program behavior is undefined, but the compiler is not required to provide you with a diagnostic (error/warning). https://en.cppreference.com/w/cpp/language/definition @nlohmann MSVC provides tooling to help catch this, might be worth looking into. https://devblogs.microsoft.com/oldnewthing/20160803-00/?p=94015 |
Thanks for your reply, basically I had said the same thing stating that the workaround is to define JSON_DIAGNOSTICS only globally. I honestly would not expect this behaviour from an header-only library, but I understand it is a design chioice that is up to you. I would add a note to the documentation to make this more clear, issued a pull request about it. Thank you and all the best, A. |
On https://json.nlohmann.me/home/exceptions/#extended-diagnostic-messages, it states:
Maybe this should be more prominent, but it clearly states that it adds a member to the class. |
Cool, I see it has been fixed in 3.11.*! |
What is the issue you have?
If I compile a simple program using the library with JSON_DIAGNOSTICS=1 and link it with another object compiled with JSON_DIAGNOSTICS=0 this leads to a coredump (SIGSEGV).
Please describe the steps to reproduce the issue.
Consider this simple code:
It compiles and runs fine:
But if I link together with this other code (no calls performed from one to the other, but the library contains a. singleton which is executed at startup):
It cores:
Can you provide a small but working code example?
See above.
What is the expected behavior?
See above.
I suppose some internal ABI changes shape when JSON_DIAGNOSTICS=1 and this makes differently behaving code to have the same symbol/signature for the linker.
And what is the actual behavior instead?
See above.
Which compiler and operating system are you using?
Tested both on macOS Monterey 12.2.1 [compiler: Apple clang version 13.0.0 (clang-1300.0.29.30)] and FreeBSD 12.2-RELEASE-p4 [compiler: FreeBSD clang version 10.0.1 (git@github.com:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa2)]
Which version of the library did you use?
If you experience a compilation error: can you compile and run the unit tests?
Not pertinent.
The text was updated successfully, but these errors were encountered: