[libcxx-commits] [PATCH] D136050: [libc++] Fix missing requires clause on variant operator<=>

Joe Loser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 17 08:12:37 PDT 2022


jloser updated this revision to Diff 468211.
jloser added a comment.

Another test fix


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136050/new/

https://reviews.llvm.org/D136050

Files:
  libcxx/include/variant
  libcxx/test/std/utilities/variant/variant.relops/three_way.pass.cpp


Index: libcxx/test/std/utilities/variant/variant.relops/three_way.pass.cpp
===================================================================
--- libcxx/test/std/utilities/variant/variant.relops/three_way.pass.cpp
+++ libcxx/test/std/utilities/variant/variant.relops/three_way.pass.cpp
@@ -170,15 +170,11 @@
 static_assert(!three_way_comparable<HasSimpleOrdering>);
 static_assert(!three_way_comparable<std::variant<int, HasSimpleOrdering>>);
 
-static_assert( has_three_way_op<HasOnlySpaceship>);
-static_assert( has_three_way_op<std::variant<int, HasOnlySpaceship>>);
+static_assert(has_three_way_op<HasOnlySpaceship>);
+static_assert(!has_three_way_op<std::variant<int, HasOnlySpaceship>>);
 
-// variants containing types with unavailable operator== still exist but will
-// generate a compilation error if their operator== is invoked, so the variant
-// type here participates when asked for operator== and operator<=> even though
-// it would actually fail.
 static_assert(!three_way_comparable<HasOnlySpaceship>);
-static_assert( three_way_comparable<std::variant<int, HasOnlySpaceship>>);
+static_assert(!three_way_comparable<std::variant<int, HasOnlySpaceship>>);
 
 static_assert( has_three_way_op<HasFullOrdering>);
 static_assert( has_three_way_op<std::variant<int, HasFullOrdering>>);
Index: libcxx/include/variant
===================================================================
--- libcxx/include/variant
+++ libcxx/include/variant
@@ -1638,7 +1638,7 @@
 
 #  if _LIBCPP_STD_VER > 17
 
-template <class... _Types>
+template <class... _Types> requires (three_way_comparable<_Types> && ...)
 _LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<compare_three_way_result_t<_Types>...>
 operator<=>(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
   using __variant_detail::__visitation::__variant;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136050.468211.patch
Type: text/x-patch
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221017/7fdd336f/attachment.bin>


More information about the libcxx-commits mailing list