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. |
nlohmann
left a comment
There was a problem hiding this comment.
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
|
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. |
gregmarr
left a comment
There was a problem hiding this comment.
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:
NaNvalues always comparefalse/unordered when compared to themselves, otherNaNs, 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
lhsandrhsand 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:
boolandstd::partial::ordering.The goal was to find visually distinguishable names for
trueandfalse.T/F,t/f,tr/fawere all ruled out because they look too similar (in my editor anyway).f_and_taren't perfect but the best I've come up with so far.value_t::discardedto the list of types and updated tables.NaNandjson(value_t::discarded)to the list of values and updated tables.test-comparison_legacybased onunit-comparison.cppbut 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::rangesrequirementsUnlike 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_implsatisfies thestd::bidirectional_iteratorconcept anditeration_proxy_valuesatisfies thestd::input_iteratorconcept.The
apply*()functions included in an earlier revision were moved into a separate PR: #3450To Do:
JSON_LEGACY_COMPARISON=1be added to CI?JSON_LEGACY_COMPARISONbe 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