From patchwork Fri Aug 23 12:44:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1976041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TfLyKQN+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wr0DD67t2z1yXY for ; Fri, 23 Aug 2024 22:45:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8183D3875467 for ; Fri, 23 Aug 2024 12:45:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 5B86A3861036 for ; Fri, 23 Aug 2024 12:45:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B86A3861036 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 5B86A3861036 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724417120; cv=none; b=TYfs0zx2yFk/i9Cf/Gcn8oZUG8LiehFy4tmUqwOpRTe4oe/Q8pUyXmus9e0jIWtF1bSmwiU9yq6ZX74Bc03woCs/8lF6nQeby8Fx2KmYKX3o3RxSBF06CK2lXVH0Yna2p4R+N9LHKI9YK0ZpweRzRdLN8nA1jifSS5u3KuXEV9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724417120; c=relaxed/simple; bh=wVJhCG5XZjpbiYRpjzLT3IFjmGv3uFLl8VNrCD/yfBM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=siJqCXmDj7lcjXpK3nI5rJtth2obPLbnKpX8CAMnNERs5X69Gwk+YTNT8n15vd5fl0gZuafYIEqp+4RPTQI6rv+2gGlKt/7NSwRmbD/K/keUI8zCQEDsNhM0QQKoHvARjeYr0iV6zBBy2Zx3BS2ncCpEGoqG0gMaDG34GqtLjPE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724417118; 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=i/1Fv0VSEatOsgjt5OCiZg2+CDXevyd6ixRaWXF6vhc=; b=TfLyKQN+W6lF3qvzreBnBxICRV8Wxy22vsZkoB/K3kNbV6/l4e8QL3U9VDYpYcJ2R6jPrE Aj88vSjC2XmW+SCOTNbaUhsHqgzfC0nPuIqhRBHCmY4qTksi3qR68lTWnwt4nCGz+MTsXq JBQ9C1fp6wV7ln8Gxp9hnKVr/E44KcA= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-35-OfRMo9UON0eKV0zeCZebIg-1; Fri, 23 Aug 2024 08:45:15 -0400 X-MC-Unique: OfRMo9UON0eKV0zeCZebIg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0FE0C19560AD; Fri, 23 Aug 2024 12:45:14 +0000 (UTC) Received: from localhost (unknown [10.42.28.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4CA9C19560AA; Fri, 23 Aug 2024 12:45:13 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Implement LWG 3746 for std::optional Date: Fri, 23 Aug 2024 13:44:57 +0100 Message-ID: <20240823124512.966125-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.5 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_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- This avoids constraint recursion in operator<=> for std::optional. The resolution was approved in Kona 2022. libstdc++-v3/ChangeLog: * include/std/optional (__is_derived_from_optional): New concept. (operator<=>): Use __is_derived_from_optional. * testsuite/20_util/optional/relops/lwg3746.cc: New test. --- libstdc++-v3/include/std/optional | 12 +++++++++-- .../20_util/optional/relops/lwg3746.cc | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/optional/relops/lwg3746.cc diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional index 6651686cd1d..933a5b15e56 100644 --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -1581,9 +1581,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return !__rhs; } #endif // three-way-comparison +#if __cpp_lib_concepts // _GLIBCXX_RESOLVE_LIB_DEFECTS // 4072. std::optional comparisons: constrain harder -#if __cpp_lib_concepts # define _REQUIRES_NOT_OPTIONAL(T) requires (!__is_optional_v) #else # define _REQUIRES_NOT_OPTIONAL(T) @@ -1675,8 +1675,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return !__rhs || __lhs >= *__rhs; } #ifdef __cpp_lib_three_way_comparison + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3746. optional's spaceship with U with a type derived from optional + // causes infinite constraint meta-recursion + template + concept __is_derived_from_optional = requires (const _Tp& __t) { + [](const optional<_Up>&){ }(__t); + }; + template - requires (!__is_optional_v<_Up>) + requires (!__is_derived_from_optional<_Up>) && three_way_comparable_with<_Up, _Tp> constexpr compare_three_way_result_t<_Tp, _Up> operator<=> [[nodiscard]] (const optional<_Tp>& __x, const _Up& __v) diff --git a/libstdc++-v3/testsuite/20_util/optional/relops/lwg3746.cc b/libstdc++-v3/testsuite/20_util/optional/relops/lwg3746.cc new file mode 100644 index 00000000000..46065f8e901 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/optional/relops/lwg3746.cc @@ -0,0 +1,20 @@ +// { dg-do compile { target c++20 } } + +// LWG 3746. optional's spaceship with U with a type derived from optional +// causes infinite constraint meta-recursion + +#include + +struct S : std::optional +{ + bool operator==(const S&) const; + bool operator<(const S&) const; + bool operator>(const S&) const; + bool operator<=(const S&) const; + bool operator>=(const S&) const; +}; + +auto cmp(const S& s, const std::optional& o) +{ + return s <=> o; +}