Commit f214ffb3 by Jonathan Wakely

libstdc++: Simplify constraints on std::compare_three_way

The __3way_builtin_ptr_cmp concept can use three_way_comparable_with to
check whether <=> is valid. Doing that makes it obvious that the
disjunction on compare_three_way::operator() is redundant, because
the second constraint subsumes the first.

The workaround for PR c++/91073 can also be removed as that bug is fixed
now.

	* libsupc++/compare (__detail::__3way_builtin_ptr_cmp): Use
	three_way_comparable_with.
	(__detail::__3way_cmp_with): Remove workaround for fixed bug.
	(compare_three_way::operator()): Remove redundant constraint from
	requires-clause.
	(__detail::_Synth3way::operator()): Use three_way_comparable_with
	instead of workaround.
	* testsuite/18_support/comparisons/object/93479.cc: Prune extra
	output due to simplified constraints on compare_three_way::operator().
parent 83b02010
2020-01-29 Jonathan Wakely <jwakely@redhat.com> 2020-01-29 Jonathan Wakely <jwakely@redhat.com>
* libsupc++/compare (__detail::__3way_builtin_ptr_cmp): Use
three_way_comparable_with.
(__detail::__3way_cmp_with): Remove workaround for fixed bug.
(compare_three_way::operator()): Remove redundant constraint from
requires-clause.
(__detail::_Synth3way::operator()): Use three_way_comparable_with
instead of workaround.
* testsuite/18_support/comparisons/object/93479.cc: Prune extra
output due to simplified constraints on compare_three_way::operator().
PR libstdc++/93479 PR libstdc++/93479
* libsupc++/compare (__3way_builtin_ptr_cmp): Require <=> to be valid. * libsupc++/compare (__3way_builtin_ptr_cmp): Require <=> to be valid.
* testsuite/18_support/comparisons/object/93479.cc: New test. * testsuite/18_support/comparisons/object/93479.cc: New test.
......
...@@ -525,26 +525,20 @@ namespace std ...@@ -525,26 +525,20 @@ namespace std
// BUILTIN-PTR-THREE-WAY(T, U) // BUILTIN-PTR-THREE-WAY(T, U)
template<typename _Tp, typename _Up> template<typename _Tp, typename _Up>
concept __3way_builtin_ptr_cmp concept __3way_builtin_ptr_cmp
= requires(_Tp&& __t, _Up&& __u) = three_way_comparable_with<_Tp, _Up>
{ static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u); }
&& convertible_to<_Tp, const volatile void*> && convertible_to<_Tp, const volatile void*>
&& convertible_to<_Up, const volatile void*> && convertible_to<_Up, const volatile void*>
&& ! requires(_Tp&& __t, _Up&& __u) && ! requires(_Tp&& __t, _Up&& __u)
{ operator<=>(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); } { operator<=>(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); }
&& ! requires(_Tp&& __t, _Up&& __u) && ! requires(_Tp&& __t, _Up&& __u)
{ static_cast<_Tp&&>(__t).operator<=>(static_cast<_Up&&>(__u)); }; { static_cast<_Tp&&>(__t).operator<=>(static_cast<_Up&&>(__u)); };
// FIXME: workaround for PR c++/91073
template<typename _Tp, typename _Up>
concept __3way_cmp_with = three_way_comparable_with<_Tp, _Up>;
} // namespace __detail } // namespace __detail
// [cmp.object], typename compare_three_way // [cmp.object], typename compare_three_way
struct compare_three_way struct compare_three_way
{ {
template<typename _Tp, typename _Up> template<typename _Tp, typename _Up>
requires (__detail::__3way_cmp_with<_Tp, _Up> requires three_way_comparable_with<_Tp, _Up>
|| __detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
constexpr auto constexpr auto
operator()(_Tp&& __t, _Up&& __u) const noexcept operator()(_Tp&& __t, _Up&& __u) const noexcept
{ {
...@@ -919,7 +913,7 @@ namespace std ...@@ -919,7 +913,7 @@ namespace std
{ __u < __t } -> convertible_to<bool>; { __u < __t } -> convertible_to<bool>;
} }
{ {
if constexpr (__3way_cmp_with<_Tp, _Up>) if constexpr (three_way_comparable_with<_Tp, _Up>)
return __t <=> __u; return __t <=> __u;
else else
{ {
......
...@@ -42,3 +42,5 @@ test02() ...@@ -42,3 +42,5 @@ test02()
std::compare_three_way{}(x, ""); // { dg-error "no match" } std::compare_three_way{}(x, ""); // { dg-error "no match" }
std::compare_three_way{}("", x); // { dg-error "no match" } std::compare_three_way{}("", x); // { dg-error "no match" }
} }
// { dg-prune-output "in requirements with" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment