-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Initialization different between gcc/clang #2311
Comments
Related: #2046 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Here is another test case (using g++-8.4 with
|
The same bug when parsing from a string, my MVE is
On gcc 10.2. the output is
on clang 10.0.1:
The expected result would be at least consistent, to me the clang behaviour seems preferable. Tested on latest release, 3.9.1 |
And as pointed to in the linked issues, it's actually about the brace initialization. If it were possible to have the clang behaviour on gcc, that would be nice, as then one can just consistently use braces, whereas now attention is needed to whether you're building an array/object with multiple keys, or initializing from an existing json. Anyway, I can now work around this by using parentheses for the constructors where appropriate, i.e. the following works in the toy example (and can be used in my actual code):
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
See the comments in #2583 and https://json.nlohmann.me/home/faq/#brace-initialization-yields-arrays for an explanation as to why the bug was closed as wontfix. |
What is the issue you have?
Initialization seems to differ between clang and gcc (have not yet tried MSVC):
I.e., in gcc this creates an array with an object as its first element; in clang it creates an object.
Please describe the steps to reproduce the issue.
Running example: https://godbolt.org/z/7r76TE
Can you provide a small but working code example?
As above.
What is the expected behavior?
Consistent initialization between compilers for the same code.
And what is the actual behavior instead?
Different values per compiler.
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchThe text was updated successfully, but these errors were encountered: