From patchwork Fri Aug 2 20:50:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 95235 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02962385E458 for ; Fri, 2 Aug 2024 20:51:37 +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 60C56385DDDC for ; Fri, 2 Aug 2024 20:51:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60C56385DDDC 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 60C56385DDDC 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=1722631863; cv=none; b=fJIXO4gkME5WVBYjuKhJiKPAa6a/5A6fYltClk9OlzYnimE+O3KCAO49AHwe6bwzQgD63cPfZdwGB67DlP7zqOW2O6YkUw8UgZ0k3HwwZWdP8mkWIwYlXXkpQMJl7BuCXOTh3P8d+m2Ho0pM7yGI8WakCUTUMOiI1vUe5uDvWzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722631863; c=relaxed/simple; bh=9PbHB60iyB8xMLVzRMspo1ld5o2qnVymbRIX5IAmTUs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sKDLQeF3uVUVJV3DPef8q3vlKqcyfDwxCRPcct0edtDEk19Zc9wcaavr88QXUJiQKW9TmC/KEkOM+aA7+JwSbpsyT2FgAns9g6CI/LkaG8ATlsEPCPkDIqnZjPta7GH5Iq2NXVFQSPH4Jl6/FNfkpJfBpxSWBCz6mKCgQG5gMZA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722631861; 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=aVUnF6aQvt3YF3RUlUbMuYCUn4tXySBLAEsAqyHuoG4=; b=QjDLXSDmTastKNkntzd9irazFw0jXepOEYD5IrJnNqTsCJyxbbMURBkFXlU6jssasfea9l bDqrJXzA07IlstRU3jYgyx1yAKMaYpH2tyZalKKiKccA/wzWZTlnp9SwuDUIjD1GULNlm/ Mam9em1YP+LoOAe+ufHuj8iPT0p4uPk= 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-643-fpKFqn3LNMO8Zs7N1NA0ug-1; Fri, 02 Aug 2024 16:50:58 -0400 X-MC-Unique: fpKFqn3LNMO8Zs7N1NA0ug-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 11BB91955D44; Fri, 2 Aug 2024 20:50:57 +0000 (UTC) Received: from localhost (unknown [10.42.28.21]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 17FF91955E80; Fri, 2 Aug 2024 20:50:55 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Do not use deduced return type for std::forward_like Date: Fri, 2 Aug 2024 21:50:06 +0100 Message-ID: <20240802205054.545397-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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, SPF_HELO_NONE, SPF_NONE, TXREP 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~patchwork=sourceware.org@gcc.gnu.org This isn't properly tested so I'm not pushing it, but I'm sharing it now for comment. -- >8 -- Inspired by https://github.com/llvm/llvm-project/issues/101614 this replaces the deduced return type of std::forward_like with a type trait to compute that type. libstdc++-v3/ChangeLog: * include/bits/move.h (__forward_like_impl): New metafunction to compute the return type of std::forward_like. (forward_like, __like_t): Use it. * testsuite/20_util/forward_like/2_neg.cc: Adjust expected errors. --- libstdc++-v3/include/bits/move.h | 45 +++++++++---------- .../testsuite/20_util/forward_like/2_neg.cc | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index bb200c95964..15b7cd07fce 100644 --- a/libstdc++-v3/include/bits/move.h +++ b/libstdc++-v3/include/bits/move.h @@ -88,31 +88,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __glibcxx_forward_like // C++ >= 23 template - [[nodiscard]] - constexpr decltype(auto) - forward_like(_Up&& __x) noexcept - { - constexpr bool __as_rval = is_rvalue_reference_v<_Tp&&>; - - if constexpr (is_const_v>) - { - using _Up2 = remove_reference_t<_Up>; - if constexpr (__as_rval) - return static_cast(__x); - else - return static_cast(__x); - } - else - { - if constexpr (__as_rval) - return static_cast&&>(__x); - else - return static_cast<_Up&>(__x); - } - } + struct __forward_like_impl + { +#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_reference) + template using __remove_ref_t = __remove_reference(_Xp); +#else + template using __remove_ref_t = remove_reference_t<_Xp>; +#endif + template + using _Copy_const = __conditional_t, const _Yp, _Yp>; + template + using _Override_ref = __conditional_t, + __remove_ref_t<_Yp>&&, _Yp&>; + using type = _Override_ref<_Tp&&, _Copy_const<__remove_ref_t<_Tp>, + __remove_ref_t<_Up>>>; + }; template - using __like_t = decltype(std::forward_like<_Tp>(std::declval<_Up>())); + using __like_t = typename __forward_like_impl<_Tp, _Up>::type; + + template + [[nodiscard]] + constexpr __like_t<_Tp, _Up> + forward_like(_Up&& __x) noexcept + { return static_cast<__like_t<_Tp, _Up>>(__x); } #endif /** diff --git a/libstdc++-v3/testsuite/20_util/forward_like/2_neg.cc b/libstdc++-v3/testsuite/20_util/forward_like/2_neg.cc index ff835af1915..f6e98420a9a 100644 --- a/libstdc++-v3/testsuite/20_util/forward_like/2_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward_like/2_neg.cc @@ -7,4 +7,4 @@ auto x1 = std::forward_like(1); // { dg-error "here" } auto x2 = std::forward_like(1); // { dg-error "here" } // { dg-error "forming reference to qualified function" "" { target *-*-* } 0 } -// { dg-prune-output "inconsistent deduction for auto return type" } // PR111484 +// { dg-prune-output "no matching function" }