From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E5B8A38460B4 for ; Wed, 3 Apr 2024 10:53:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5B8A38460B4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E5B8A38460B4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712141631; cv=none; b=qEyBt3ckSP7qoErPXa3uQDpMtGGWfAZ29IBmhjo6gHcZAgzn/CVQqfs3fSHR1rgVG9nez5Xcptr7yqtGqWbr2+YL5lcHFXWGljfC+e9IADKKMEybNwEG+SITRVPy/iUjW680ZAhrn169Q/CAdtpOWq8vUR5uwbBH+CWNmC5FWro= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712141631; c=relaxed/simple; bh=LUFemLIp3bQG5quseXwGMAuW+10/GeTfygEvy/Gyivc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wJnornn6GfcCoO55NKIkRnDdgkTI3+AZw3xcJF35/LxioSw5xjgDr8/0G9a9QgAbe6IKEG5yunRhDnE5BGRsxynLqC3KKwnUC4AA6+gNcW6wGsHeowQOCkqRF6vu39g5IEmg9v5fWinLLRV8jSPfhfetHg5GeuIeR/Dp+z3jH8E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712141629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NkLmUs3pkR3t43c+Vds3RJ6UUq9xe7MinuOJOBOXbvU=; b=QA1wqM5mEHU9B6FoMuVNBico+UXdc8Xb00ioITLBfGW/tZZMMcSnYEDpUKbvEAsWgCCMMR FtdgY5Ne4nBBJyxD/V7qF6oNUmjBtpI1EfbimjtASZ3MNYPqrE0n6GLHeF+XQuy6Zzlcnz meWz68zczhcDawCgpcxfkC70XaZeT/I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-Z_dSOgPFPdqwejJwobr2Kw-1; Wed, 03 Apr 2024 06:53:48 -0400 X-MC-Unique: Z_dSOgPFPdqwejJwobr2Kw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA08688CC45; Wed, 3 Apr 2024 10:53:47 +0000 (UTC) Received: from localhost (unknown [10.42.28.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9968E1121312; Wed, 3 Apr 2024 10:53:47 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Reverse arguments in constraint for std::optional's <=> [PR104606] Date: Wed, 3 Apr 2024 11:53:23 +0100 Message-ID: <20240403105343.222775-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,URI_HEX autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Pushed to trunk. Backports likely to follow. -- >8 -- 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. --- libstdc++-v3/include/std/optional | 2 +- .../20_util/optional/relops/104606.cc | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/20_util/optional/relops/104606.cc 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; -- 2.44.0