-
-
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
Fix C++20/gcc-12 issues (Part 2) #3446
Fix C++20/gcc-12 issues (Part 2) #3446
Conversation
b47ac94
to
c974073
Compare
3671fa0
to
1953b1d
Compare
Ignore the "Disable regression test for 3070 on GCC <8.4" commit for now. I rebased incorrectly against a local branch instead of upstream/develop. I'll fix it when I push the next set of changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I keep making comments to things you are then commenting yourself, I submit my first bunch of comments now... :)
@falbrechtskirchinger Is there anything I can do to help here? |
Yes. Please review and merge. :-) I see a minor merge conflict in the documentation that I can resolve. Otherwise, this PR is done. |
There's also a Codacy issue that needs to be ignored in the comparison tests. |
I marked it as ignored. |
0e3c6f3
to
165fed1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I would feel more comfortable if @gregmarr could have a second look at this before merging. |
I'd also like to have one last look at the tables in the unit test and spot-check them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor questions/observations, otherwise LGTM.
165fed1
to
d199626
Compare
Fixes nlohmann#3130. Related discussion: nlohmann#3408
Document how CMake chooses which C++ standard version to use when building tests.
d199626
to
4f744f4
Compare
I've fixed a misaligned column numbers comment in the unit test, and added I've also completed my spot-check of the unit test tables and added a @nlohmann Ready for merge pending all-green CI. |
Thanks a lot!!! |
@falbrechtskirchinger I wonder if this is the reason for the issues we had with differing compiler behaviors: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html |
Interesting find. I just briefly scanned through it. Based on that, my initial thought is no. Our issue is specific to enums and how overload resolution is specified for them. I wish I knew what the proper process is to bring (perceived) language defects to the attention of the standard committee. Maybe I should just email the authors of that paper. |
@falbrechtskirchinger Ah, that's right. I just remembered that there was surprising results in the comparisons, not what exactly they were. |
This is part 2 of #3379.
Add the spaceship operator
Part 1 had to disable some comparisons in unit tests because of incorrect results due to standard library code using 3-way comparison which, in the absence of a user-defined operator, compares the result of implicit conversions.
In part 2 we implement the spaceship operator and fix some inconsistencies in the old comparison code:
NaN
values always comparefalse
/unordered when compared to themselves, otherNaN
s, or other numbers.false
/unordered to themselves or any other value, unless the legacy comparison behavior is explicitly enabled by defining the macroJSON_LEGACY_COMPARISON=1
.When the legacy behavior is selected, operations that were computed as an odd number of inverses of other operations always return
true
. Example:Given two values
lhs
andrhs
and at least one of them being a discarded value.GCC ignores user-defined
operator<=>
for enumerated types when rewriting operators. Clang, MSVC, and ICC do not. (ICC manages to produce an incorrect result anyway o.O.)I've filed a bug with GCC but do agree now that GCC is following the letter of the standard. If anyone knows where to best raise concerns over a language defect, let me know.
it's easy enough to work around by defining
operator<
and explicitly delegating tooperator<=>
. Currently only enabled for GCC but almost guaranteed to be required for (some versions of) ICC.The unit tests were updated in several ways:
bool
andstd::partial::ordering
.The goal was to find visually distinguishable names for
true
andfalse
.T
/F
,t
/f
,tr
/fa
were all ruled out because they look too similar (in my editor anyway).f_
and_t
aren't perfect but the best I've come up with so far.value_t::discarded
to the list of types and updated tables.NaN
andjson(value_t::discarded)
to the list of values and updated tables.test-comparison_legacy
based onunit-comparison.cpp
but withJSON_LEGACY_COMPARISON=1
.unit-class_parser.cpp
, which breaks with the new comparison behavior, continues to work in legacy mode.Fix iterators to meet (more)
std::ranges
requirementsUnlike the unconstrained algorithms, which only declared named requirements, constrained algorithms and views use concepts to enforce requirements.
Some iterators did not meet enough of those requirements.
In this PR we ensure that
iter_impl
satisfies thestd::bidirectional_iterator
concept anditeration_proxy_value
satisfies thestd::input_iterator
concept.The
apply*()
functions included in an earlier revision were moved into a separate PR: #3450To Do:
JSON_LEGACY_COMPARISON=1
be added to CI?JSON_LEGACY_COMPARISON
be renamed toJSON_LEGACY_DISCARDED_COMPARISON
(or something else entirely) now that it only applies to discarded values?JSON_LEGACY_COMPARISON
.JSON_HAS_THREE_WAY_COMPARISON
.JSON_HAS_RANGES
.Fixes #3130.
Fixes #3409.
Related discussion: #3408