[libcxx-commits] [libcxx] [libc++] Fix std::variant comparators not working on recursive instantiations (PR #182238)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 6 09:45:49 PST 2026
================
@@ -317,6 +317,71 @@ void test_relational() {
#endif
}
+struct A1 {
+ bool operator==(const A1&) const { return true; }
+ bool operator!=(const A1&) const { return true; }
+ bool operator<(const A1&) const { return true; }
+ bool operator>(const A1&) const { return true; }
+ bool operator<=(const A1&) const { return true; }
+ bool operator>=(const A1&) const { return true; }
+};
+struct A2 {
+ bool operator==(const A2&) const { return true; }
+ bool operator!=(const A2&) const { return true; }
+ bool operator<(const A2&) const { return true; }
+ bool operator>(const A2&) const { return true; }
+ bool operator<=(const A2&) const { return true; }
+ bool operator>=(const A2&) const { return true; }
+};
+
+struct Array;
+
+using Var1 = std::variant<A1, Array>;
+using Var2 = std::variant<A2, Array>;
+
+struct Array {
+ Var1* ptr;
+
+ template <class Other>
+ friend constexpr bool operator==(const Array& lhs, const Other& rhs) {
+ return *lhs.ptr == *rhs.ptr;
+ }
+
+ template <class Other>
+ friend constexpr bool operator!=(const Array& lhs, const Other& rhs) {
+ return *lhs.ptr != *rhs.ptr;
+ }
+
+ template <class Other>
+ friend constexpr bool operator<(const Array& lhs, const Other& rhs) {
+ return *lhs.ptr < *rhs.ptr;
+ }
+
+ template <class Other>
+ friend constexpr bool operator>(const Array& lhs, const Other& rhs) {
+ return *lhs.ptr > *rhs.ptr;
+ }
+
+ template <class Other>
+ friend constexpr bool operator<=(const Array& lhs, const Other& rhs) {
+ return *lhs.ptr <= *rhs.ptr;
+ }
+
+ template <class Other>
+ friend constexpr bool operator>=(const Array& lhs, const Other& rhs) {
+ return *lhs.ptr >= *rhs.ptr;
+ }
+};
+
+void test_recursive() {
----------------
ldionne wrote:
```suggestion
// See https://llvm.org/PR182232
void test_recursive() {
```
https://github.com/llvm/llvm-project/pull/182238
More information about the libcxx-commits
mailing list