This is an archive of the discontinued LLVM Phabricator instance.

[libc++][spaceship] Implement `operator<=>` for `array`
ClosedPublic

Authored by H-G-Hristov on Aug 19 2022, 3:27 PM.

Details

Summary

Implements part of P1614R2 "The Mothership has Landed"

Diff Detail

Event Timeline

avogelsgesang created this revision.Aug 19 2022, 3:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2022, 3:27 PM
Herald added a subscriber: yaxunl. · View Herald Transcript
avogelsgesang requested review of this revision.Aug 19 2022, 3:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2022, 3:27 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

update review link

add AssertComparisonsReturnBool/AssertOrderReturn to test cases

Add whitespace in templates

I have some issues regarding the difference of the paper and the Standard, can you look for an LWG-issue. I couldn't find one quickly. I glossed over the rest of the patch but didn't do a real review since it's uncertain what should be implemented.

libcxx/include/array
91

Did you look for any LWG issues in this header?

P1614 states

[ Editor's note: array’s comparisons move to be hidden friends to allow for use as non-type template parameters. All the other containers drop != and, if they have relational operators, those get replaced with a <=>. ]

Change 22.3.2 [array.syn]:
The operator== has been removed from the header and operator<=> isn't added/

Change 22.3.7.1 [array.overview]:

+   friend constexpr bool operator==(const array&, const array&) = default;
+   friend constexpr synth-three-way-result<value_type>
+     operator<=>(const array&, const array&);

But this doesn't match the WP. No friends and no defaulted operator==.

438
442
libcxx/test/std/containers/sequences/array/compare.pass.cpp
76

nice!

avogelsgesang added inline comments.Nov 19 2022, 8:55 PM
libcxx/include/array
91

https://cplusplus.github.io/LWG/issue3347 removed the friends again and reintroduced the free-standing comparisons again

avogelsgesang planned changes to this revision.Nov 19 2022, 8:56 PM

needs to be adjusted to use the still-to-be-introduced test utilities from https://reviews.llvm.org/D132312 is done

H-G-Hristov commandeered this revision.Apr 23 2023, 4:55 AM
H-G-Hristov added a reviewer: avogelsgesang.
H-G-Hristov marked 3 inline comments as done.
  • [libc++][spaceship] Implement operator<=> for array
H-G-Hristov marked an inline comment as done.Apr 23 2023, 9:26 AM
  • Try to fix GCC -Werror=maybe-uninitialized
  • Rebased to rerun CI

The CI failure is not related to your changes.

Is this patch ready for review or do you have more changes planned?

libcxx/include/array
438

This change is not applied.

  • Addressed review comments
H-G-Hristov marked an inline comment as done.May 3 2023, 1:25 PM

The CI failure is not related to your changes.

Is this patch ready for review or do you have more changes planned?

Yes, this patch and also the patches for vector and optionalare ready for a review.

philnik added a subscriber: philnik.May 4 2023, 4:04 PM
philnik added inline comments.
libcxx/docs/Status/Cxx20.rst
65 ↗(On Diff #519227)

Would you be interested in implementing the rest of this issue? It doesn't look too complicated.

libcxx/include/array
410–413

Let's try to not reintroduce wrong formatting.

libcxx/test/std/containers/sequences/array/compare.fail.cpp
0
0

Could you make this a .verify.cpp while you're at it?

libcxx/test/std/containers/sequences/array/compare.pass.cpp
1

Thanks for improving this test!

libcxx/test/std/containers/sequences/array/compare.three_way.compile.fail.cpp
1 ↗(On Diff #519227)

Please use .verify.cpp instead.

libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp
63
72
75–77

Let's move the SFINAE test to the top of the file.

H-G-Hristov marked 7 inline comments as done.
  • Addressed review comments
H-G-Hristov marked an inline comment as done.May 5 2023, 8:37 AM

@philnik Thank you for the review!

NOTE: Changes to compare.pass.cpp were too large so git failed to match it to compare.verify.cpp.
libcxx/docs/Status/Cxx20.rst
65 ↗(On Diff #519227)

Yes, let me do it in a follow up patch.

libcxx/include/array
410–413

I replaced _LIBCPP_INLINE_VISIBILITY and applied format to the whole section.

libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp
75–77

Moved it. My original motivation was to keep the same stricture of the test as tests in:
libcxx/test/support/test_container_comparisons.h
where they use templates.

H-G-Hristov updated this revision to Diff 520076.EditedMay 6 2023, 5:44 AM
H-G-Hristov marked an inline comment as done.
  • Marked LWG3347 as complete

It was even marked as Nothing to Do: https://libcxx.llvm.org/Status/Spaceship.html

H-G-Hristov added inline comments.May 6 2023, 10:48 AM
libcxx/docs/Status/Cxx20.rst
65 ↗(On Diff #519227)

Let me correct myself, the std::pair's part is already implemented. Marked the issue as completed.

Mordante accepted this revision as: Mordante.May 7 2023, 8:51 AM

All my comments have been addressed. I leave the final approval to @philnik.

philnik accepted this revision.May 7 2023, 12:20 PM
This revision is now accepted and ready to land.May 7 2023, 12:20 PM
This revision was landed with ongoing or failed builds.May 8 2023, 7:03 AM
This revision was automatically updated to reflect the committed changes.