From patchwork Thu Sep 11 12:16:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 120073 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 3FDD83858412 for ; Thu, 11 Sep 2025 12:19:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FDD83858412 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Cltkry7u 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.133.124]) by sourceware.org (Postfix) with ESMTP id E096D3858422 for ; Thu, 11 Sep 2025 12:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E096D3858422 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 E096D3858422 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=1757593069; cv=none; b=w0gZDZnBvPSl7EI2F/OF5P9uhsKtTN5qCIjsFhPskfItF8zX8hqqS+rblPu19cERY+LNo5XMvD6QOW3smf3cmuYYwEbI0UBg33RO8X/jnMKkxbIJtmnmXMJD+MUbpSuXAT3cEQJqzKJa+x2QL3gNj21SnQTRS5O8ef78wYnkuJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757593069; c=relaxed/simple; bh=sECXPdEORsCkfQ8Fh3Qc0VDzhPEx3mhPXzJUY0BCvhg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oQUacU5bHe6btsBIMKKboie76t8yIIGDUuhVO4MVwmLxelthtB+9nvXkSoTsj/OsD1S2K4sLqzdpQ6uhFM//mBsQskV8SeRhpPgPScN+R39i/8cQqNRhm9ujz36Mxy4O4Y+rXt00FqmXc5+yILbGNqS53vcfdC0VggaPzqAQB6M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E096D3858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757593067; 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: in-reply-to:in-reply-to:references:references; bh=8luS4A1LfpRoqdQY1LEUufks0Zy8DHINK5+JdpG9rPU=; b=Cltkry7uOfMp/eAlopHNZUC846dstmAW8A+7FnGvPayCFRTXxa5+pmma77Hw1sisKTAB19 TgAySgNbYu62b8AdmxeYb/G6eclj6xaoWh0HKmWokq7VruRAYKcE/nMqCR4YRg3cI6KnNv bRAtHKM0dWp1odo3I0+52kll2Qwbgdw= Received: from mx-prod-mc-01.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-28-_mOJ8LhNP_qY039dn6qIXw-1; Thu, 11 Sep 2025 08:17:44 -0400 X-MC-Unique: _mOJ8LhNP_qY039dn6qIXw-1 X-Mimecast-MFC-AGG-ID: _mOJ8LhNP_qY039dn6qIXw_1757593063 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C56A11954194; Thu, 11 Sep 2025 12:17:43 +0000 (UTC) Received: from zen.kayari.org (unknown [10.42.28.196]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AFF721944CCA; Thu, 11 Sep 2025 12:17:42 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Use consteval for _S_noexcept() helper functions Date: Thu, 11 Sep 2025 13:16:24 +0100 Message-ID: <20250911121739.1538375-2-jwakely@redhat.com> In-Reply-To: <20250911121739.1538375-1-jwakely@redhat.com> References: <20250911121739.1538375-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-MFC-PROC-ID: 4a6H5S525CXWPx_0dSfJlNx6-3gEg7B_j7nUKG1nivo_1757593063 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PROLO_LEO1, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=unavailable 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 These _S_noexcept() functions are only used in noexcept-specifiers and never need to be called at runtime. They can be immediate functions, i.e. consteval. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (_IterMove::_S_noexcept) (_IterSwap::_S_noexcept): Change constexpr to consteval. * include/bits/ranges_base.h (_Begin::_S_noexcept) (_End::_S_noexcept, _RBegin::_S_noexcept, _REnd::_S_noexcept) (_Size::_S_noexcept, _Empty::_S_noexcept, _Data::_S_noexcept): Likewise. * include/std/concepts (_Swap::_S_noexcept): Likewise. --- Tested powerpc64-linux. libstdc++-v3/include/bits/iterator_concepts.h | 4 ++-- libstdc++-v3/include/bits/ranges_base.h | 14 +++++++------- libstdc++-v3/include/std/concepts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index 979039e7da53..fd91b22d75a5 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -141,21 +141,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { // Instead of decltype(std::move(*E)) we define the type as the // return type of std::move, i.e. remove_reference_t&&. // N.B. the use of decltype(declval()) instead of just X&& is // needed for function reference types, see PR libstdc++/119469. using type = decltype(std::declval>>()); }; template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (__adl_imove<_Tp>) return noexcept(iter_move(std::declval<_Tp>())); else return noexcept(*std::declval<_Tp>()); } public: // The result type of iter_move(std::declval<_Tp>()) @@ -877,21 +877,21 @@ namespace ranges { iter_value_t<_Xp> __old_value(iter_move(__x)); *__x = iter_move(__y); return __old_value; } struct _IterSwap { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (__adl_iswap<_Tp, _Up>) return noexcept(iter_swap(std::declval<_Tp>(), std::declval<_Up>())); else if constexpr (indirectly_readable<_Tp> && indirectly_readable<_Up> && swappable_with, iter_reference_t<_Up>>) return noexcept(ranges::swap(*std::declval<_Tp>(), *std::declval<_Up>())); diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index c1a9f6a90009..1c4bf432c8f4 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -99,21 +99,21 @@ namespace ranges // Namespace for helpers for the customization points. namespace __access { using std::ranges::__detail::__maybe_borrowed_range; using std::__detail::__range_iter_t; struct _Begin { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (is_array_v>) return true; else if constexpr (__member_begin<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(std::declval<_Tp&>().begin())); else return noexcept(_GLIBCXX_AUTO_CAST(begin(std::declval<_Tp&>()))); } @@ -150,21 +150,21 @@ namespace ranges concept __adl_end = __class_or_enum> && requires(_Tp& __t) { { _GLIBCXX_AUTO_CAST(end(__t)) } -> sentinel_for<__range_iter_t<_Tp>>; }; struct _End { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (is_bounded_array_v>) return true; else if constexpr (__member_end<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(std::declval<_Tp&>().end())); else return noexcept(_GLIBCXX_AUTO_CAST(end(std::declval<_Tp&>()))); } @@ -207,21 +207,21 @@ namespace ranges concept __reversable = requires(_Tp& __t) { { _Begin{}(__t) } -> bidirectional_iterator; { _End{}(__t) } -> same_as; }; struct _RBegin { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (__member_rbegin<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(std::declval<_Tp&>().rbegin())); else if constexpr (__adl_rbegin<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(rbegin(std::declval<_Tp&>()))); else { if constexpr (noexcept(_End{}(std::declval<_Tp&>()))) { @@ -265,21 +265,21 @@ namespace ranges && requires(_Tp& __t) { { _GLIBCXX_AUTO_CAST(rend(__t)) } -> sentinel_for(__t)))>; }; struct _REnd { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (__member_rend<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(std::declval<_Tp&>().rend())); else if constexpr (__adl_rend<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(rend(std::declval<_Tp&>()))); else { if constexpr (noexcept(_Begin{}(std::declval<_Tp&>()))) { @@ -335,21 +335,21 @@ namespace ranges { _End{}(__t) } -> sized_sentinel_for; __detail::__to_unsigned_like(_End{}(__t) - _Begin{}(__t)); }; struct _Size { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (is_bounded_array_v>) return true; else if constexpr (__member_size<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(std::declval<_Tp&>().size())); else if constexpr (__adl_size<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(size(std::declval<_Tp&>()))); else if constexpr (__sentinel_size<_Tp>) return noexcept(_End{}(std::declval<_Tp&>()) @@ -415,21 +415,21 @@ namespace ranges { _Begin{}(__t) } -> forward_iterator; bool(_Begin{}(__t) == _End{}(__t)); }; struct _Empty { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (__member_empty<_Tp>) return noexcept(bool(std::declval<_Tp&>().empty())); else if constexpr (__size0_empty<_Tp>) return noexcept(_Size{}(std::declval<_Tp&>()) == 0); else return noexcept(bool(_Begin{}(std::declval<_Tp&>()) == _End{}(std::declval<_Tp&>()))); } @@ -461,21 +461,21 @@ namespace ranges { _GLIBCXX_AUTO_CAST(__t.data()) } -> __pointer_to_object; }; template concept __begin_data = contiguous_iterator<__range_iter_t<_Tp>>; struct _Data { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (__member_data<_Tp>) return noexcept(_GLIBCXX_AUTO_CAST(std::declval<_Tp&>().data())); else return noexcept(_Begin{}(std::declval<_Tp&>())); } public: template<__maybe_borrowed_range _Tp> diff --git a/libstdc++-v3/include/std/concepts b/libstdc++-v3/include/std/concepts index 5899f032434a..d9920a8f20a8 100644 --- a/libstdc++-v3/include/std/concepts +++ b/libstdc++-v3/include/std/concepts @@ -197,21 +197,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = (std::__detail::__class_or_enum> || std::__detail::__class_or_enum>) && requires(_Tp&& __t, _Up&& __u) { swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); }; struct _Swap { private: template - static constexpr bool + static consteval bool _S_noexcept() { if constexpr (__adl_swap<_Tp, _Up>) return noexcept(swap(std::declval<_Tp>(), std::declval<_Up>())); else return is_nothrow_move_constructible_v> && is_nothrow_move_assignable_v>; } public: