[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 10:55:18 PDT 2022


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

Add requires clause to synopsis in both `<variant>` and the `three_way_pass.cpp`.


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
@@ -12,7 +12,7 @@
 
 // template <class... Types> class variant;
 
-// template<class... Types>
+// template <class... Types> requires (three_way_comparable<Types> && ...)
 //   constexpr std::common_comparison_category_t<
 //     std::compare_three_way_result_t<Types>...>
 //   operator<=>(const variant<Types...>& t, const variant<Types...>& u);
@@ -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
@@ -165,7 +165,7 @@
   template <class... Types>
   constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&);
 
-  template <class... Types>
+  template <class... Types> requires (three_way_comparable<Types> && ...)
   constexpr common_comparison_category_t<compare_three_way_result_t<Types>...>
     operator<=>(const variant<Types...>&, const variant<Types...>&);           // since C++20
 
@@ -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.468259.patch
Type: text/x-patch
Size: 2605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221017/134ddea1/attachment.bin>


More information about the libcxx-commits mailing list