From patchwork Tue May 5 15:03:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 134484 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D5C934BA9018 for ; Tue, 5 May 2026 15:04:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5C934BA9018 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=RHhCi0xT 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 1BB6E4BA79B7 for ; Tue, 5 May 2026 15:03:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BB6E4BA79B7 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 1BB6E4BA79B7 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=1777993438; cv=none; b=b93FdCDRvG3rALEIHplZ9i32ZLOy1LfXR1FBEq+caYpl9ehezKumeVM1Id3XQRHT9OHsC6b/aAofmMffOca/RP6mYqscSwpxfeQQ2gk6BvVZSzjaNR4ZwE/Na9sTmopIZRkCosd4dLW2eJ6UP6wpBjfZpynz2N4ua82FpJAZWVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777993438; c=relaxed/simple; bh=mFR358pi0UNkpZTHJTrcq+6l9H4ICb9QfburFWU0fEw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Z6h0oeJ2c2Wu7MkhTAm01bTBcYDAXGqhEEMzjmzF/iAB0kVYSXCkHc7GEaIwJebO8kWXQmklB61xpY/SL1GwKiB8Ft/FXxXnMr8a8+lcXAy9jshHpe0ziJSQB4sxGrWfsj/CpD3ErzT+nEi4yhgM9uJor2Kg/PcPaJM2hMcf3QY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BB6E4BA79B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777993437; 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=S7qAEEevpCg/sYUkySSu6EE7nux3qQGjHgMOEpEzk/A=; b=RHhCi0xT+iuQkO/zezhUFpaIoXSRa4xs5o4/FM+R1OBJcVuuIj8N7BikJTs8DYOKenm6c/ czo/8zblrbkSScUZlE7QZ2xrUK8wWDyrVJQE83ulRJt/fDFVYNIxe5XSBJ4xA2y3Y/iiKu sm2XbjfG7jxf9fV+dITe2ABvRJ78I9I= Received: from mx-prod-mc-03.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-177-d_noVaaeP6yZZfrSI1SJ7w-1; Tue, 05 May 2026 11:03:56 -0400 X-MC-Unique: d_noVaaeP6yZZfrSI1SJ7w-1 X-Mimecast-MFC-AGG-ID: d_noVaaeP6yZZfrSI1SJ7w_1777993434 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1F2DA19560BB; Tue, 5 May 2026 15:03:54 +0000 (UTC) Received: from zen.kayari.org (unknown [10.44.50.93]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 25AAC196B0A2; Tue, 5 May 2026 15:03:52 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH 1/3] libstdc++: Replace uses of EBO with [[no_unique_address]] Date: Tue, 5 May 2026 16:03:17 +0100 Message-ID: <20260505150351.209503-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: 4IzLRWIwQAsHcMJaUM_i7uzZwTvIcAHtBS-0TKvZCy0_1777993434 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.9 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 Clang 9 added support for [[__no_unique_address__]] and we don't support Intel icc any longer, so we can remove the code in that works around the absence of that attribute. We can also address a FIXME in and replace uses of EBO with the attribute. libstdc++-v3/ChangeLog: * include/bits/shared_ptr_base.h (_Sp_ebo_helper): Simplify by using [[__no_unique_address__]] instead of EBO. Use the attribute unconditionally for the unstable ABI. (_Sp_counted_deleter::_Impl): Adjust uses of _Sp_ebo_helper. (_Sp_counted_ptr_inplace::_Impl): Likewise. * include/std/tuple (_Head_base): Remove implementation for compilers that don't support [[__no_unique_address__]]. Use the attribute unconditionally for the unstable ABI. --- Tested x86_64-linux. libstdc++-v3/include/bits/shared_ptr_base.h | 65 +++++++++---------- libstdc++-v3/include/std/tuple | 69 ++++----------------- 2 files changed, 43 insertions(+), 91 deletions(-) diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index b92e3a4c90e4..3a966eddc06c 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -513,57 +513,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void _Sp_counted_ptr::_M_dispose() noexcept { } - // FIXME: once __has_cpp_attribute(__no_unique_address__)) is true for - // all supported compilers we can greatly simplify _Sp_ebo_helper. +#if ! __has_cpp_attribute(__no_unique_address__) +#error "support for [[__no_unique_address__]] attribute is required" +#endif + +#if ! _GLIBCXX_INLINE_VERSION // N.B. unconditionally applying the attribute could change layout for // final types, which currently cannot use EBO so have a unique address. - - template + template struct _Sp_ebo_helper; +#else + template + struct _Sp_ebo_helper; +#endif - /// Specialization using EBO. - template - struct _Sp_ebo_helper<_Nm, _Tp, true> : private _Tp + /// Specialization using [[no_unique_address]]. + template + struct _Sp_ebo_helper<_Tp, true> { - explicit _Sp_ebo_helper(const _Tp& __tp) : _Tp(__tp) { } - explicit _Sp_ebo_helper(_Tp&& __tp) : _Tp(std::move(__tp)) { } - - static _Tp& - _S_get(_Sp_ebo_helper& __eboh) { return static_cast<_Tp&>(__eboh); } + [[__no_unique_address__]] _Tp _M_obj; }; - /// Specialization not using EBO. - template - struct _Sp_ebo_helper<_Nm, _Tp, false> +#if ! _GLIBCXX_INLINE_VERSION + /// Specialization not using [[no_unique_address]]. + template + struct _Sp_ebo_helper<_Tp, false> { - explicit _Sp_ebo_helper(const _Tp& __tp) : _M_tp(__tp) { } - explicit _Sp_ebo_helper(_Tp&& __tp) : _M_tp(std::move(__tp)) { } - - static _Tp& - _S_get(_Sp_ebo_helper& __eboh) - { return __eboh._M_tp; } - - private: - _Tp _M_tp; + _Tp _M_obj; }; +#endif // Support for custom deleter and/or allocator template class _Sp_counted_deleter final : public _Sp_counted_base<_Lp> { - class _Impl : _Sp_ebo_helper<0, _Deleter>, _Sp_ebo_helper<1, _Alloc> + class _Impl { - typedef _Sp_ebo_helper<0, _Deleter> _Del_base; - typedef _Sp_ebo_helper<1, _Alloc> _Alloc_base; + _Sp_ebo_helper<_Deleter> _M_d; + _Sp_ebo_helper<_Alloc> _M_a; public: _Impl(_Ptr __p, _Deleter __d, const _Alloc& __a) noexcept - : _Del_base(std::move(__d)), _Alloc_base(__a), _M_ptr(__p) + : _M_d{std::move(__d)}, _M_a{__a}, _M_ptr(__p) { } - _Deleter& _M_del() noexcept { return _Del_base::_S_get(*this); } - _Alloc& _M_alloc() noexcept { return _Alloc_base::_S_get(*this); } + _Deleter& _M_del() noexcept { return _M_d._M_obj; } + _Alloc& _M_alloc() noexcept { return _M_a._M_obj; } _Ptr _M_ptr; }; @@ -645,14 +640,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp> { - class _Impl : _Sp_ebo_helper<0, _Alloc> + class _Impl { - typedef _Sp_ebo_helper<0, _Alloc> _A_base; + _Sp_ebo_helper<_Alloc> _M_a; public: - explicit _Impl(_Alloc __a) noexcept : _A_base(__a) { } + explicit _Impl(_Alloc __a) noexcept : _M_a{std::move(__a)} { } - _Alloc& _M_alloc() noexcept { return _A_base::_S_get(*this); } + _Alloc& _M_alloc() noexcept { return _M_a._M_obj; } __gnu_cxx::__aligned_buffer<__remove_cv_t<_Tp>> _M_storage; }; diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index f7caa79cda04..32800d8d7752 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -68,7 +68,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class tuple; +#if ! __has_cpp_attribute(__no_unique_address__) +#error "support for [[__no_unique_address__]] attribute is required" +#endif + /// @cond undocumented +#if ! _GLIBCXX_INLINE_VERSION template struct __is_empty_non_tuple : is_empty<_Tp> { }; @@ -76,17 +81,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __is_empty_non_tuple> : false_type { }; - // Use the Empty Base-class Optimization for empty, non-final types. + // Use [[no_unique_address]] for empty, non-final types. template using __empty_not_final = __conditional_t<__is_final(_Tp), false_type, __is_empty_non_tuple<_Tp>>; +#else + // For the unstable ABI we always use [[no_unique_address]]. + template + using __empty_not_final = true_type; +#endif template::value> struct _Head_base; -#if __has_cpp_attribute(__no_unique_address__) template struct _Head_base<_Idx, _Head, true> { @@ -141,61 +150,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION [[__no_unique_address__]] _Head _M_head_impl; }; -#else - template - struct _Head_base<_Idx, _Head, true> - : public _Head - { - constexpr _Head_base() - : _Head() { } - - constexpr _Head_base(const _Head& __h) - : _Head(__h) { } - - constexpr _Head_base(const _Head_base&) = default; - constexpr _Head_base(_Head_base&&) = default; - - template - constexpr _Head_base(_UHead&& __h) - : _Head(std::forward<_UHead>(__h)) { } - - _GLIBCXX20_CONSTEXPR - _Head_base(allocator_arg_t, __uses_alloc0) - : _Head() { } - - template - _GLIBCXX20_CONSTEXPR - _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a) - : _Head(allocator_arg, *__a._M_a) { } - - template - _GLIBCXX20_CONSTEXPR - _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a) - : _Head(*__a._M_a) { } - - template - _GLIBCXX20_CONSTEXPR - _Head_base(__uses_alloc0, _UHead&& __uhead) - : _Head(std::forward<_UHead>(__uhead)) { } - - template - _GLIBCXX20_CONSTEXPR - _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead) - : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { } - - template - _GLIBCXX20_CONSTEXPR - _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead) - : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { } - - static constexpr _Head& - _M_head(_Head_base& __b) noexcept { return __b; } - - static constexpr const _Head& - _M_head(const _Head_base& __b) noexcept { return __b; } - }; -#endif +#if ! _GLIBCXX_INLINE_VERSION template struct _Head_base<_Idx, _Head, false> { @@ -250,6 +206,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Head _M_head_impl; }; +#endif #if __cpp_lib_tuple_like // >= C++23 struct __tuple_like_tag_t { explicit __tuple_like_tag_t() = default; }; From patchwork Tue May 5 15:03:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 134485 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id B76354B9DB74 for ; Tue, 5 May 2026 15:04:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B76354B9DB74 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=X7iop6sC 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 2A4EF4BA79B9 for ; Tue, 5 May 2026 15:03:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A4EF4BA79B9 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 2A4EF4BA79B9 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=1777993438; cv=none; b=O8o1dGUG7Wkal/VJ0enmWyujBeBafUv5i2pGA5dgGPNbj/CybDQdM32u9kqxGGd97HcKO0blm10R2wKQhS/ViGPuxNLHPi+TA/alC07wZmdJDZ1kJqcq7mtggQq5P+HA+BcDgWvbkkcfC5DSjp10GVz75X3OXOlmvtqK/2gxTh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777993438; c=relaxed/simple; bh=NZNWanN7QzZuXSkE38PIxRzRvoK4nB+VdGSDPax9z9k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TeqcafzEDQWh3egbe5ucvVZgVz7qUtDH1xGSI4JeOOvPPishv1Eo/U3jVKL6Wg4s6Owxj11PgsOxIlXpjRmz6Yb7u0ZqQbfu63FLFdKbXCuY5gH7m0XxbRCGaUtZFpVwxXaijml08RRxeY2gi7SemwQur7fNUJ0kccTlKizR2IM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A4EF4BA79B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777993437; 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=eT9P/azdPSkgqMQ2UOjQcx9BNuXpCY0fkPS6xZ6Q1VE=; b=X7iop6sC0vcBFBnWixU3JP5hDEFWiuHCuNBnkCXljMPAXw/i0YwY5JF7J8Jq++oNxHWXkw GIgsEnoQkmYd2D6qIBPMoiDXAAE+6Rq5zw9jPWoKAzotuOdmiPcPoqXRvV0nvQrqrdXjLq VpcvbuIWnum7ilHflUiHeCRH9ipYpes= Received: from mx-prod-mc-05.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-531-geNV9FPgPgqg5xFl-SaK3A-1; Tue, 05 May 2026 11:03:56 -0400 X-MC-Unique: geNV9FPgPgqg5xFl-SaK3A-1 X-Mimecast-MFC-AGG-ID: geNV9FPgPgqg5xFl-SaK3A_1777993435 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ABFE619560B9; Tue, 5 May 2026 15:03:55 +0000 (UTC) Received: from zen.kayari.org (unknown [10.44.50.93]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8F3A1196B0A2; Tue, 5 May 2026 15:03:54 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH 2/3] libstdc++: Simplify std::shared_ptr internals Date: Tue, 5 May 2026 16:03:18 +0100 Message-ID: <20260505150351.209503-2-jwakely@redhat.com> In-Reply-To: <20260505150351.209503-1-jwakely@redhat.com> References: <20260505150351.209503-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: PzccRegVhlHzzOkfyXO_gxMQ0w1ZWWvaUDdCoxh3uYw_1777993435 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.9 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, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 Now that we don't use the EBO we can flatten the class layout by removing some _Impl classes. libstdc++-v3/ChangeLog: * include/bits/out_ptr.h (out_ptr_t::_Impl::~_Impl): Adjust access to shared_ptr internals. * include/bits/shared_ptr_base.h (_Sp_counted_deleter): Remove _Impl class and replace _M_impl with the data members it contained. (_Sp_counted_ptr_inplace): Likewise. --- Tested x86_64-linux. libstdc++-v3/include/bits/out_ptr.h | 2 +- libstdc++-v3/include/bits/shared_ptr_base.h | 60 ++++++--------------- 2 files changed, 18 insertions(+), 44 deletions(-) diff --git a/libstdc++-v3/include/bits/out_ptr.h b/libstdc++-v3/include/bits/out_ptr.h index cc5a8a3adacb..f5fdc6cf910f 100644 --- a/libstdc++-v3/include/bits/out_ptr.h +++ b/libstdc++-v3/include/bits/out_ptr.h @@ -257,7 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION auto& __pi = _M_smart._M_refcount._M_pi; if (_Sp __ptr = _M_smart.get()) - static_cast<_Scd*>(__pi)->_M_impl._M_ptr = __ptr; + static_cast<_Scd*>(__pi)->_M_ptr = __ptr; else // Destroy the control block manually without invoking deleter. std::__exchange(__pi, nullptr)->_M_destroy(); } diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 3a966eddc06c..cf1be953af2c 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -547,32 +547,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class _Sp_counted_deleter final : public _Sp_counted_base<_Lp> { - class _Impl - { - _Sp_ebo_helper<_Deleter> _M_d; - _Sp_ebo_helper<_Alloc> _M_a; - - public: - _Impl(_Ptr __p, _Deleter __d, const _Alloc& __a) noexcept - : _M_d{std::move(__d)}, _M_a{__a}, _M_ptr(__p) - { } - - _Deleter& _M_del() noexcept { return _M_d._M_obj; } - _Alloc& _M_alloc() noexcept { return _M_a._M_obj; } - - _Ptr _M_ptr; - }; - public: using __allocator_type = __alloc_rebind<_Alloc, _Sp_counted_deleter>; // __d(__p) must not throw. _Sp_counted_deleter(_Ptr __p, _Deleter __d) noexcept - : _M_impl(__p, std::move(__d), _Alloc()) { } + : _M_del{std::move(__d)}, _M_alloc{}, _M_ptr(__p) { } // __d(__p) must not throw. _Sp_counted_deleter(_Ptr __p, _Deleter __d, const _Alloc& __a) noexcept - : _M_impl(__p, std::move(__d), __a) { } + : _M_del{std::move(__d)}, _M_alloc{__a}, _M_ptr(__p) { } #pragma GCC diagnostic push // PR tree-optimization/122197 #pragma GCC diagnostic ignored "-Wfree-nonheap-object" @@ -582,12 +566,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION virtual void _M_dispose() noexcept - { _M_impl._M_del()(_M_impl._M_ptr); } + { _M_del._M_obj(_M_ptr); } virtual void _M_destroy() noexcept { - __allocator_type __a(_M_impl._M_alloc()); + __allocator_type __a(_M_alloc._M_obj); __allocated_ptr<__allocator_type> __guard_ptr{ __a, this }; this->~_Sp_counted_deleter(); } @@ -598,19 +582,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_rtti // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2400. shared_ptr's get_deleter() should use addressof() - return __ti == typeid(_Deleter) - ? std::__addressof(_M_impl._M_del()) - : nullptr; -#else - return nullptr; + if (__ti == typeid(_Deleter)) + return std::__addressof(_M_del._M_obj); #endif + return nullptr; } private: #ifdef __glibcxx_out_ptr template friend class out_ptr_t; #endif - _Impl _M_impl; + + _Sp_ebo_helper<_Deleter> _M_del; + _Sp_ebo_helper<_Alloc> _M_alloc; + _Ptr _M_ptr; }; // helpers for make_shared / allocate_shared @@ -640,25 +625,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp> { - class _Impl - { - _Sp_ebo_helper<_Alloc> _M_a; - - public: - explicit _Impl(_Alloc __a) noexcept : _M_a{std::move(__a)} { } - - _Alloc& _M_alloc() noexcept { return _M_a._M_obj; } - - __gnu_cxx::__aligned_buffer<__remove_cv_t<_Tp>> _M_storage; - }; - public: using __allocator_type = __alloc_rebind<_Alloc, _Sp_counted_ptr_inplace>; // Alloc parameter is not a reference so doesn't alias anything in __args template _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args) - : _M_impl(__a) + : _M_alloc{__a} { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2070. allocate_shared should use allocator_traits::construct @@ -674,14 +647,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION virtual void _M_dispose() noexcept { - allocator_traits<_Alloc>::destroy(_M_impl._M_alloc(), _M_ptr()); + allocator_traits<_Alloc>::destroy(_M_alloc._M_obj, _M_ptr()); } // Override because the allocator needs to know the dynamic type virtual void _M_destroy() noexcept { - __allocator_type __a(_M_impl._M_alloc()); + __allocator_type __a(_M_alloc._M_obj); __allocated_ptr<__allocator_type> __guard_ptr{ __a, this }; this->~_Sp_counted_ptr_inplace(); } @@ -711,9 +684,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } __remove_cv_t<_Tp>* - _M_ptr() noexcept { return _M_impl._M_storage._M_ptr(); } + _M_ptr() noexcept { return _M_storage._M_ptr(); } - _Impl _M_impl; + _Sp_ebo_helper<_Alloc> _M_alloc; + __gnu_cxx::__aligned_buffer<__remove_cv_t<_Tp>> _M_storage; }; #ifdef __glibcxx_smart_ptr_for_overwrite // C++ >= 20 && HOSTED From patchwork Tue May 5 15:03:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 134486 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 069B14BA9011 for ; Tue, 5 May 2026 15:06:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 069B14BA9011 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=RESp0boc 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 F27E34BA9010 for ; Tue, 5 May 2026 15:04:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F27E34BA9010 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 F27E34BA9010 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=1777993442; cv=none; b=NLExbtJ7uAbrC7VEIxnR7ztZSMdolNsEdC/yKMooIyzkzdChWJ6jNH3iTCcYtzM/TGnqTtHIOGGqfqgESzeANJ+hOgJ1EXa8XZaorkCB/5iqbnVAtOff7E4mr06T5H8A13YV7rbHE4sOfTT1gZDZy0pXg9HgT1pKnp8pdgUjjxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777993442; c=relaxed/simple; bh=xZnCOrcpLt34WO+ndvmuaew7sx1YsI1nQOdo1vBDX3U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OBBQV4/sOJB3YjEl2WskIHc0y5m3eJrOWiH6yJL/07EmKtxCHh6q7fLEh8bZ3lAWAdZvsp6VT3anoczNfyCl/olyA1iOs6XybMUNN6Hg4dF6gdHXL4pSIywF2IhJhUiIl9Fs8adk/z5SAHP+0xeE43KNZ3vssLoeOi/tO0DOMMY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F27E34BA9010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777993441; 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=3tOGpMCoshG1WMWdfwKjtOCWJVum6iSO36Ul00wioyc=; b=RESp0bocwzwg7TZIRK1I+BYEgo/C2sJPBa6+xnfiHMJcCPXVDla/Bw2WVVHduezXe09ky5 U7QV0nzA/frqXmfc70J2jZbkP4MIxLLAASKMGGUQYmOKOt6TdWeHyEkbEFvdTY2ed938P+ 5rabHYwkMbe+oUqDI7s+eLzimNARWSQ= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-3te1idQOMiew-mFt_sOaPg-1; Tue, 05 May 2026 11:03:58 -0400 X-MC-Unique: 3te1idQOMiew-mFt_sOaPg-1 X-Mimecast-MFC-AGG-ID: 3te1idQOMiew-mFt_sOaPg_1777993437 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9EAD51800347; Tue, 5 May 2026 15:03:57 +0000 (UTC) Received: from zen.kayari.org (unknown [10.44.50.93]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 47C9C1944CED; Tue, 5 May 2026 15:03:55 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH 3/3] libstdc++: Remove non-concepts fallback for std::make_shared_for_overwrite Date: Tue, 5 May 2026 16:03:19 +0100 Message-ID: <20260505150351.209503-3-jwakely@redhat.com> In-Reply-To: <20260505150351.209503-1-jwakely@redhat.com> References: <20260505150351.209503-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: ZWmuIXotQGB5Sekpa5quQyudoDVieRdgZIJ7GoMzcAU_1777993437 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_H4, RCVD_IN_MSPIKE_WL, 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 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 Clang 10 added support for concepts, so we no longer need to support C++20 compilers that don't define __cpp_concepts. libstdc++-v3/ChangeLog: * include/bits/shared_ptr.h (_UnboundedArray, _BoundedArray) (_NotUnboundedArray): Remove fallback definition for C++20 compilers that don't define __cpp_concepts. * include/bits/shared_ptr_base.h (_Sp_counted_ptr_inplace): Remove fallback declaration of _Sp_overwrite_tag partial specialization. --- Tested x86_64-linux. libstdc++-v3/include/bits/shared_ptr.h | 18 ------------------ libstdc++-v3/include/bits/shared_ptr_base.h | 5 ----- 2 files changed, 23 deletions(-) diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index fd00384df223..ada32d3d3cb9 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -114,38 +114,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __glibcxx_shared_ptr_arrays >= 201707L // Constraint for overloads taking array types with unknown bound, U[]. -#if __cpp_concepts template requires is_array_v<_Tp> && (extent_v<_Tp> == 0) using _UnboundedArray = _Tp; -#else - template - using _UnboundedArray - = __enable_if_t<__is_array_unknown_bounds<_Tp>::value, _Tp>; -#endif // Constraint for overloads taking array types with known bound, U[N]. -#if __cpp_concepts template requires (extent_v<_Tp> != 0) using _BoundedArray = _Tp; -#else - template - using _BoundedArray - = __enable_if_t<__is_array_known_bounds<_Tp>::value, _Tp>; -#endif #if __glibcxx_smart_ptr_for_overwrite // Constraint for overloads taking either non-array or bounded array, U[N]. -#if __cpp_concepts template requires (!is_array_v<_Tp>) || (extent_v<_Tp> != 0) using _NotUnboundedArray = _Tp; -#else - template - using _NotUnboundedArray - = __enable_if_t::value, _Tp>; -#endif #endif // smart_ptr_for_overwrite #endif // shared_ptr_arrays diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index cf1be953af2c..a64131bb9e12 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -696,14 +696,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Partial specialization used for make_shared_for_overwrite(). // This partial specialization is used when the allocator's value type // is the special _Sp_overwrite_tag type. -#if __cpp_concepts template requires is_same_v class _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> final -#else - template class _Alloc, _Lock_policy _Lp> - class _Sp_counted_ptr_inplace<_Tp, _Alloc<_Sp_overwrite_tag>, _Lp> final -#endif : public _Sp_counted_base<_Lp> { [[no_unique_address]] _Alloc _M_alloc;