LWG3175 identifies that the common_reference requirement for
swappable_with is over-constraining and doesn't need to concern itself
with cv- or reference qualifiers.
Details
- Reviewers
zoecarver curdeius • Quuxplusone - Group Reviewers
Restricted Project - Commits
- rGcedd07df5136: [libcxx] fixes `common_reference` requirement for `swappable_with`
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
LGTM % nits.
libcxx/test/std/concepts/concepts.lang/concept.swappable/swappable_with.compile.pass.cpp | ||
---|---|---|
671 | FWIW, you could just capitalize the letter p on line 680 and then you wouldn't need this function. | |
681 | As-IMO-always with constexpr tests, it'd be better style to write assert(a1.m == -5 && a2.m == 5); return true; This would incidentally match the snippet in https://cplusplus.github.io/LWG/issue3175 a little closer, too, FWIW. However, maybe a bigger surprise with this test is that it's all constexpr. LWG3175 tests the non-compile-time case, and doesn't mention the constexpr keyword at all. Either way is probably equivalent for testing purposes, but this gets back to my usual "cruft" complaint: there's a lot of keywords not pulling their weight in here. ;) | |
684 | Please add a "simple test" too. I think the simple test is just static_assert(std::swappable_with<N::Proxy, N::A>); static_assert(std::swappable_with<N::A, N::Proxy>); (and if you wanted to eliminate the useless namespace N, that'd be cool; but I imagine you don't, because it's part of the LWG3175 snippet) |
gets CI passing
libcxx/test/std/concepts/concepts.lang/concept.swappable/swappable_with.compile.pass.cpp | ||
---|---|---|
671 | I found it surprising that [concept.swappable] did this, so I preserved it. | |
681 |
Do you have a technical reason for preferring this?
Eh, I suppose I could make this a run-time test if you insist, but the regression test is aimed at the concept std::swappable_with, not std::ranges::swap.
I don't see the connection, but I also don't see which keywords aren't doing their job. | |
684 | The crux of LWG3175 is that Proxy and A don't share a common reference (and so swappable_with<Proxy, A> == false). The defect was originally filed to correct the example only, and IIRC Casey noticed that the common_reference requirement was also out of whack. I'm not sure there is a companion simple test for this, but I'm happy to be proven wrong. |
Please improve commit title and add a proper commit message to the review.
I also like to see it pass the CI.
libcxx/test/std/concepts/concepts.lang/concept.swappable/swappable_with.compile.pass.cpp | ||
---|---|---|
681 |
I personally like the style with separate asserts better, especially if it gets more complex. For example I dislike https://reviews.llvm.org/D97115#inline-910325, but assert can't be used in C++11. In this case I would like it to better match the wording of LWG3175. |
libcxx/test/std/concepts/concepts.lang/concept.swappable/swappable_with.compile.pass.cpp | ||
---|---|---|
681 | I don't like assert in constexpr diagnostics, but matching LWG3175 code is probably best. |
FWIW, you could just capitalize the letter p on line 680 and then you wouldn't need this function.