From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 93657384772F; Wed, 3 Apr 2024 10:53:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93657384772F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712141603; bh=PaGUM2xoefHEn7PhhKHZI3It8pzfjxmp/w5BJYuwLho=; h=From:To:Subject:Date:From; b=B4RsmzJf3BKrRY+WzbFfFE4htIOOiVWRoIr3rNTl+KFn1zk2FD3lS/Kt59qWFO1hu F8SAMoJXgBCVCuUZxSlvhNpmseCERHCtB0NeKrFlXjp/AyBgo2LecXrBdGG3lH+VNo XInbRWIGdNbZq3mE8INYkOoWi2gxGQhJGG1WJoW4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-9771] libstdc++: Reverse arguments in constraint for std::optional's <=> [PR104606] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: b2460d621efe740bd95ad41afef6d806ec1bd9c7 X-Git-Newrev: 7f65d8267fbfd19cf21a3dc71d27e989e75044a3 Message-Id: <20240403105323.93657384772F@sourceware.org> Date: Wed, 3 Apr 2024 10:53:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7f65d8267fbfd19cf21a3dc71d27e989e75044a3 commit r14-9771-g7f65d8267fbfd19cf21a3dc71d27e989e75044a3 Author: Jonathan Wakely Date: Wed Mar 27 21:51:13 2024 +0000 libstdc++: Reverse arguments in constraint for std::optional's <=> [PR104606] This is a workaround for a possible compiler bug that causes constraint recursion in the operator<=>(const optional&, const U&) overload. libstdc++-v3/ChangeLog: PR libstdc++/104606 * include/std/optional (operator<=>(const optional&, const U&)): Reverse order of three_way_comparable_with template arguments. * testsuite/20_util/optional/relops/104606.cc: New test. Diff: --- libstdc++-v3/include/std/optional | 2 +- .../testsuite/20_util/optional/relops/104606.cc | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional index 1e88e8b8880..3507c36a4d8 100644 --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -1430,7 +1430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef __cpp_lib_three_way_comparison template 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; } diff --git a/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc b/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc new file mode 100644 index 00000000000..2b8df245219 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc @@ -0,0 +1,18 @@ +// { dg-do compile { target c++17 } } + +// Bug 104606 comparison operator resolution with std::optional and -std=c++20 + +#include +#include +#include + +struct Value : std::variant> { }; + +struct Comparator { + template bool operator<=(const T &) { return true; } +}; + +std::optional o; +Comparator c; + +auto x = c <= o;