@@ -1430,7 +1430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifdef __cpp_lib_three_way_comparison
template<typename _Tp, typename _Up>
requires (!__is_optional_v<_Up>)
- && three_way_comparable_with<_Tp, _Up>
+ && three_way_comparable_with<_Up, _Tp>
constexpr compare_three_way_result_t<_Tp, _Up>
operator<=>(const optional<_Tp>& __x, const _Up& __v)
{ return bool(__x) ? *__x <=> __v : strong_ordering::less; }
new file mode 100644
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++17 } }
+
+// Bug 104606 comparison operator resolution with std::optional and -std=c++20
+
+#include <optional>
+#include <variant>
+#include <vector>
+
+struct Value : std::variant<std::vector<Value>> { };
+
+struct Comparator {
+ template <typename T> bool operator<=(const T &) { return true; }
+};
+
+std::optional<Value> o;
+Comparator c;
+
+auto x = c <= o;