| Message ID | 20260505150351.209503-3-jwakely@redhat.com |
|---|---|
| State | New |
| Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> 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 <patchwork@sourceware.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <jwakely@redhat.com> 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
| Series |
[1/3] libstdc++: Replace uses of EBO with [[no_unique_address]]
|
|
Commit Message
Jonathan Wakely
May 5, 2026, 3:03 p.m. UTC
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(-)
Comments
On Tue, May 5, 2026 at 5:04 PM Jonathan Wakely <jwakely@redhat.com> wrote: > 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<typename _Tp> > requires is_array_v<_Tp> && (extent_v<_Tp> == 0) > using _UnboundedArray = _Tp; > Could we replace this constrained alias with requires/concept on the function? that are using it? This version was always deductible, so shouldn't make difference. May however change mangling. > -#else > - template<typename _Tp> > - 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<typename _Tp> > requires (extent_v<_Tp> != 0) > using _BoundedArray = _Tp; > -#else > - template<typename _Tp> > - 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<typename _Tp> > requires (!is_array_v<_Tp>) || (extent_v<_Tp> != 0) > using _NotUnboundedArray = _Tp; > -#else > - template<typename _Tp> > - using _NotUnboundedArray > - = __enable_if_t<!__is_array_unknown_bounds<_Tp>::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<non-array>(). > // This partial specialization is used when the allocator's value type > // is the special _Sp_overwrite_tag type. > -#if __cpp_concepts > template<typename _Tp, typename _Alloc, _Lock_policy _Lp> > requires is_same_v<typename _Alloc::value_type, _Sp_overwrite_tag> > class _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> final > -#else > - template<typename _Tp, template<typename> 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; > -- > 2.54.0 > >
On Wed, 6 May 2026 at 08:57, Tomasz Kaminski <tkaminsk@redhat.com> wrote: > > > > On Tue, May 5, 2026 at 5:04 PM Jonathan Wakely <jwakely@redhat.com> wrote: >> >> 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<typename _Tp> >> requires is_array_v<_Tp> && (extent_v<_Tp> == 0) >> using _UnboundedArray = _Tp; > > Could we replace this constrained alias with requires/concept on the function? > that are using it? This version was always deductible, so shouldn't make difference. I wanted to do that, but just above this diff we have: // Constraint for overloads taking non-array types. #if __cpp_concepts && __glibcxx_type_trait_variable_templates template<typename _Tp> requires (!is_array_v<_Tp>) using _NonArray = _Tp; #else template<typename _Tp> using _NonArray = __enable_if_t<!is_array<_Tp>::value, _Tp>; #endif That *can't* use a requires-clause, it has to continue using a constrained alias for C++11 mode. That means that std::make_shared and std::allocate_shared are constrained using the alias: template<typename _Yp, typename _Alloc, typename... _Args> friend shared_ptr<_NonArray<_Yp>> allocate_shared(const _Alloc&, _Args&&...); template<typename _Yp, typename... _Args> friend shared_ptr<_NonArray<_Yp>> make_shared(_Args&&...); So for consistency I didn't want to change how the C++20 overloads are defined: template<typename _Yp, typename _Alloc> friend shared_ptr<_UnboundedArray<_Yp>> allocate_shared(const _Alloc&, size_t); template<typename _Yp> friend shared_ptr<_UnboundedArray<_Yp>> make_shared(size_t); We could do it for the C++20 ones. I think it would still work correctly to have the C++11 overloads constrained using the alias and the later ones constrained using a requires-clause. The conditions that enable each overload are mutually exclusive, so there would be no concerns about the interaction between the different types of constraints on overload resolution. There would still be exactly one viable candidate for any given call. For make_shared_for_overwrite we don't have to worry about the interaction with the C++11 overload, because there is no C++11 overload. So we could change that to use a requires-clause, but it would still look inconsistent with the related (not "_for_overwrite") function templates. Also, because these make_shared* and allocate_shared* function templates are all friends, if we use a requires-clause it needs to be repeated in two places. So yes, it would be possible. I considered it, and decided to keep the aliases (at least for now).
On Wed, May 6, 2026 at 11:01 AM Jonathan Wakely <jwakely@redhat.com> wrote: > On Wed, 6 May 2026 at 08:57, Tomasz Kaminski <tkaminsk@redhat.com> wrote: > > > > > > > > On Tue, May 5, 2026 at 5:04 PM Jonathan Wakely <jwakely@redhat.com> > wrote: > >> > >> 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<typename _Tp> > >> requires is_array_v<_Tp> && (extent_v<_Tp> == 0) > >> using _UnboundedArray = _Tp; > > > > Could we replace this constrained alias with requires/concept on the > function? > > that are using it? This version was always deductible, so shouldn't make > difference. > > I wanted to do that, but just above this diff we have: > > // Constraint for overloads taking non-array types. > #if __cpp_concepts && __glibcxx_type_trait_variable_templates > template<typename _Tp> > requires (!is_array_v<_Tp>) > using _NonArray = _Tp; > #else > template<typename _Tp> > using _NonArray = __enable_if_t<!is_array<_Tp>::value, _Tp>; > #endif > > That *can't* use a requires-clause, it has to continue using a > constrained alias for C++11 mode. > > That means that std::make_shared and std::allocate_shared are > constrained using the alias: > > template<typename _Yp, typename _Alloc, typename... _Args> > friend shared_ptr<_NonArray<_Yp>> > allocate_shared(const _Alloc&, _Args&&...); > > template<typename _Yp, typename... _Args> > friend shared_ptr<_NonArray<_Yp>> > make_shared(_Args&&...); > > So for consistency I didn't want to change how the C++20 overloads are > defined: > > template<typename _Yp, typename _Alloc> > friend shared_ptr<_UnboundedArray<_Yp>> > allocate_shared(const _Alloc&, size_t); > > template<typename _Yp> > friend shared_ptr<_UnboundedArray<_Yp>> > make_shared(size_t); > > We could do it for the C++20 ones. I think it would still work > correctly to have the C++11 overloads constrained using the alias and > the later ones constrained using a requires-clause. The conditions > that enable each overload are mutually exclusive, so there would be no > concerns about the interaction between the different types of > constraints on overload resolution. There would still be exactly one > viable candidate for any given call. > > For make_shared_for_overwrite we don't have to worry about the > interaction with the C++11 overload, because there is no C++11 > overload. So we could change that to use a requires-clause, but it > would still look inconsistent with the related (not "_for_overwrite") > function templates. > > Also, because these make_shared* and allocate_shared* function > templates are all friends, if we use a requires-clause it needs to be > repeated in two places. > > So yes, it would be possible. I considered it, and decided to keep the > aliases (at least for now). > That makes sense, thanks for the detailed explanation.
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<typename _Tp> requires is_array_v<_Tp> && (extent_v<_Tp> == 0) using _UnboundedArray = _Tp; -#else - template<typename _Tp> - 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<typename _Tp> requires (extent_v<_Tp> != 0) using _BoundedArray = _Tp; -#else - template<typename _Tp> - 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<typename _Tp> requires (!is_array_v<_Tp>) || (extent_v<_Tp> != 0) using _NotUnboundedArray = _Tp; -#else - template<typename _Tp> - using _NotUnboundedArray - = __enable_if_t<!__is_array_unknown_bounds<_Tp>::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<non-array>(). // This partial specialization is used when the allocator's value type // is the special _Sp_overwrite_tag type. -#if __cpp_concepts template<typename _Tp, typename _Alloc, _Lock_policy _Lp> requires is_same_v<typename _Alloc::value_type, _Sp_overwrite_tag> class _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> final -#else - template<typename _Tp, template<typename> 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;