{"id":2233376,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2233376/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260506085339.325517-1-jwakely@redhat.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260506085339.325517-1-jwakely@redhat.com>","date":"2026-05-06T08:48:04","name":"[v2,1/3] libstdc++: Replace uses of EBO with [[no_unique_address]]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"9fe0b6561f7212b446ce1504fdf213473570c9be","submitter":{"id":48004,"url":"http://patchwork.ozlabs.org/api/1.1/people/48004/?format=json","name":"Jonathan Wakely","email":"jwakely@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260506085339.325517-1-jwakely@redhat.com/mbox/","series":[{"id":502950,"url":"http://patchwork.ozlabs.org/api/1.1/series/502950/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=502950","date":"2026-05-06T08:48:05","name":"[v2,1/3] libstdc++: Replace uses of EBO with [[no_unique_address]]","version":2,"mbox":"http://patchwork.ozlabs.org/series/502950/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2233376/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2233376/checks/","tags":{},"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Xzjmk6qS;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Xzjmk6qS","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","sourceware.org; arc=none smtp.remote-ip=170.10.133.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9WX65L0Jz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 20:17:09 +1000 (AEST)","from vm01.sourceware.org (localhost [IPv6:::1])\n\tby sourceware.org (Postfix) with ESMTP id 33B6D4BA79A9\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  6 May 2026 10:17:07 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id 11AE04BA23FD\n for <gcc-patches@gcc.gnu.org>; Wed,  6 May 2026 08:53:46 +0000 (GMT)","from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-yyYHEzrUMdqpa33Qp0BpyQ-1; Wed,\n 06 May 2026 04:53:43 -0400","from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id EF8EB18005B3; Wed,  6 May 2026 08:53:41 +0000 (UTC)","from zen.kayari.org (unknown [10.44.32.38])\n by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id EE1C91800240; Wed,  6 May 2026 08:53:40 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 33B6D4BA79A9","OpenDKIM Filter v2.11.0 sourceware.org 11AE04BA23FD"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 11AE04BA23FD","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 11AE04BA23FD","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778057627; cv=none;\n b=Sd7Pq2bDRjThe7FbkMG1XZEgv3Fy2/cE7bxiKIkHdqf1YC6Hl42coSprvnUmve7bOipW+JB6vhfrJjBzooiELapWWfsadJ4iAfpqCVCcIbdKxzN0WVLX8tHONv5XkCPPv/faFVKW40/ejb5YxiCIxS2YamXCHehRAGR6t1DDMS4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1778057627; c=relaxed/simple;\n bh=B7pDEpr0+fkrXRtxVSqbwRtsjOYndYyaWZ68RTI5KuM=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=AEEHjtot4z0mQxfpj1GXLfb4ku2ddeTQt5sY9nZybb+cmOYHM+oR0tNQczOmkzq2kP/pbVBB3RUAE7cM5v4xPzdD69hykiQwSI0vygb5yj+eNO4xe3cm+mlbaWQviblR+sPrLEkQWE+fRBsv630TcBgvJ+FkQyI75nb2rN0eNZA=","ARC-Authentication-Results":"i=1; sourceware.org;\n dkim=pass (1024-bit key, unprotected)\n header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Xzjmk6qS","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1778057626;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=/gLvmsU0C5sSPNYR4NT1HbrD/Fz+TQVbORtEDShrjVU=;\n b=Xzjmk6qSG7dQqhVcMTPxPw8uv5U1+LaowORajT9OMvo9DowoUbWKkI4YfOYd0og+a/k6Gc\n Rv2WhaRdZbwbVBArrE9fHPfSZbD0K9FxrI2/Sq6SNO1BRQM5hpQMxcHCPFoTJG3SvjpALv\n jDmIxn5ZgrhugCTaWwUj3yYXTSn48Vw=","X-MC-Unique":"yyYHEzrUMdqpa33Qp0BpyQ-1","X-Mimecast-MFC-AGG-ID":"yyYHEzrUMdqpa33Qp0BpyQ_1778057622","From":"Jonathan Wakely <jwakely@redhat.com>","To":"gcc-patches@gcc.gnu.org,\n\tlibstdc++@gcc.gnu.org","Subject":"[PATCH v2 1/3] libstdc++: Replace uses of EBO with\n [[no_unique_address]]","Date":"Wed,  6 May 2026 09:48:04 +0100","Message-ID":"<20260506085339.325517-1-jwakely@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.111","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"WNozS6X0qXxEdT-DpK5j1oR533F0x_1ylY8JgemkDVk_1778057622","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","Content-Transfer-Encoding":"8bit","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>,\n <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>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Clang 9 added support for [[__no_unique_address__]] and we don't support\nIntel icc any longer, so we can remove the code in <tuple> that works\naround the absence of that attribute. We can also address a FIXME in\n<bits/shared_ptr_base.h> and replace uses of EBO with the attribute.\n\nlibstdc++-v3/ChangeLog:\n\n\t* include/bits/shared_ptr_base.h (_Sp_ebo_helper): Simplify by\n\tusing [[__no_unique_address__]] instead of EBO. Use the\n\tattribute unconditionally for the unstable ABI.\n\t(_Sp_counted_deleter::_Impl): Adjust uses of _Sp_ebo_helper.\n\t(_Sp_counted_ptr_inplace::_Impl): Likewise.\n\t* include/std/tuple (_Head_base): Remove implementation for\n\tcompilers that don't support [[__no_unique_address__]]. Use the\n\tattribute unconditionally for the unstable ABI.\n---\n\nv2: Add the attribute to the data members of _Impl as well as to the\n_M_obj data member of _Sp_ebo_helper. Otherwise the _M_obj subobject is\npotentially overlapping, but the _M_ and _M_d ones are not. We need both\nto be marked with the attribute.\n\nWhat we *really* want is [[no_unique_address(expr)]] so that we can get\nrid of _Sp_ebo_helper entirely, and just do:\n\n  #if ! _GLIBCXX_INLINE_VERSION // Stable ABI\n  template<typename T> __can_overlap = !__is_final(T) && __is_empty(T);\n  #else // Unstable ABI\n  template<typename T> __can_overlap = true;\n  #endif\n  [[no_unique_address(__can_overlap<_Del>)]] _M_del;\n\nI should propose that to WG21, and if rejected just get it added to GCC\nand Clang.\n\nTested x86_64-linux.\n\n libstdc++-v3/include/bits/shared_ptr_base.h | 65 +++++++++----------\n libstdc++-v3/include/std/tuple              | 69 ++++-----------------\n 2 files changed, 43 insertions(+), 91 deletions(-)","diff":"diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h\nindex b92e3a4c90e4..3ab73f6e4a0d 100644\n--- a/libstdc++-v3/include/bits/shared_ptr_base.h\n+++ b/libstdc++-v3/include/bits/shared_ptr_base.h\n@@ -513,57 +513,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n     inline void\n     _Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() noexcept { }\n \n-  // FIXME: once __has_cpp_attribute(__no_unique_address__)) is true for\n-  // all supported compilers we can greatly simplify _Sp_ebo_helper.\n+#if ! __has_cpp_attribute(__no_unique_address__)\n+#error \"support for [[__no_unique_address__]] attribute is required\"\n+#endif\n+\n+#if ! _GLIBCXX_INLINE_VERSION\n   // N.B. unconditionally applying the attribute could change layout for\n   // final types, which currently cannot use EBO so have a unique address.\n-\n-  template<int _Nm, typename _Tp,\n-\t   bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>\n+  template<typename _Tp, bool = !__is_final(_Tp) && __is_empty(_Tp)>\n     struct _Sp_ebo_helper;\n+#else\n+  template<typename _Tp, bool = true>\n+    struct _Sp_ebo_helper;\n+#endif\n \n-  /// Specialization using EBO.\n-  template<int _Nm, typename _Tp>\n-    struct _Sp_ebo_helper<_Nm, _Tp, true> : private _Tp\n+  /// Specialization using [[no_unique_address]].\n+  template<typename _Tp>\n+    struct _Sp_ebo_helper<_Tp, true>\n     {\n-      explicit _Sp_ebo_helper(const _Tp& __tp) : _Tp(__tp) { }\n-      explicit _Sp_ebo_helper(_Tp&& __tp) : _Tp(std::move(__tp)) { }\n-\n-      static _Tp&\n-      _S_get(_Sp_ebo_helper& __eboh) { return static_cast<_Tp&>(__eboh); }\n+      [[__no_unique_address__]] _Tp _M_obj;\n     };\n \n-  /// Specialization not using EBO.\n-  template<int _Nm, typename _Tp>\n-    struct _Sp_ebo_helper<_Nm, _Tp, false>\n+#if ! _GLIBCXX_INLINE_VERSION\n+  /// Specialization not using [[no_unique_address]].\n+  template<typename _Tp>\n+    struct _Sp_ebo_helper<_Tp, false>\n     {\n-      explicit _Sp_ebo_helper(const _Tp& __tp) : _M_tp(__tp) { }\n-      explicit _Sp_ebo_helper(_Tp&& __tp) : _M_tp(std::move(__tp)) { }\n-\n-      static _Tp&\n-      _S_get(_Sp_ebo_helper& __eboh)\n-      { return __eboh._M_tp; }\n-\n-    private:\n-      _Tp _M_tp;\n+      _Tp _M_obj;\n     };\n+#endif\n \n   // Support for custom deleter and/or allocator\n   template<typename _Ptr, typename _Deleter, typename _Alloc, _Lock_policy _Lp>\n     class _Sp_counted_deleter final : public _Sp_counted_base<_Lp>\n     {\n-      class _Impl : _Sp_ebo_helper<0, _Deleter>, _Sp_ebo_helper<1, _Alloc>\n+      class _Impl\n       {\n-\ttypedef _Sp_ebo_helper<0, _Deleter>\t_Del_base;\n-\ttypedef _Sp_ebo_helper<1, _Alloc>\t_Alloc_base;\n+\t[[__no_unique_address__]] _Sp_ebo_helper<_Deleter> _M_d;\n+\t[[__no_unique_address__]] _Sp_ebo_helper<_Alloc>   _M_a;\n \n       public:\n \t_Impl(_Ptr __p, _Deleter __d, const _Alloc& __a) noexcept\n-\t: _Del_base(std::move(__d)), _Alloc_base(__a), _M_ptr(__p)\n+\t: _M_d{std::move(__d)}, _M_a{__a}, _M_ptr(__p)\n \t{ }\n \n-\t_Deleter& _M_del() noexcept { return _Del_base::_S_get(*this); }\n-\t_Alloc& _M_alloc() noexcept { return _Alloc_base::_S_get(*this); }\n+\t_Deleter& _M_del() noexcept { return _M_d._M_obj; }\n+\t_Alloc& _M_alloc() noexcept { return _M_a._M_obj; }\n \n \t_Ptr _M_ptr;\n       };\n@@ -645,14 +640,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n   template<typename _Tp, typename _Alloc, _Lock_policy _Lp>\n     class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp>\n     {\n-      class _Impl : _Sp_ebo_helper<0, _Alloc>\n+      class _Impl\n       {\n-\ttypedef _Sp_ebo_helper<0, _Alloc>\t_A_base;\n+\t[[__no_unique_address__]] _Sp_ebo_helper<_Alloc> _M_a;\n \n       public:\n-\texplicit _Impl(_Alloc __a) noexcept : _A_base(__a) { }\n+\texplicit _Impl(_Alloc __a) noexcept : _M_a{std::move(__a)} { }\n \n-\t_Alloc& _M_alloc() noexcept { return _A_base::_S_get(*this); }\n+\t_Alloc& _M_alloc() noexcept { return _M_a._M_obj; }\n \n \t__gnu_cxx::__aligned_buffer<__remove_cv_t<_Tp>> _M_storage;\n       };\ndiff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple\nindex f7caa79cda04..32800d8d7752 100644\n--- a/libstdc++-v3/include/std/tuple\n+++ b/libstdc++-v3/include/std/tuple\n@@ -68,7 +68,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n   template<typename... _Elements>\n     class tuple;\n \n+#if ! __has_cpp_attribute(__no_unique_address__)\n+#error \"support for [[__no_unique_address__]] attribute is required\"\n+#endif\n+\n   /// @cond undocumented\n+#if ! _GLIBCXX_INLINE_VERSION\n   template<typename _Tp>\n     struct __is_empty_non_tuple : is_empty<_Tp> { };\n \n@@ -76,17 +81,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n   template<typename _El0, typename... _El>\n     struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };\n \n-  // Use the Empty Base-class Optimization for empty, non-final types.\n+  // Use [[no_unique_address]] for empty, non-final types.\n   template<typename _Tp>\n     using __empty_not_final\n     = __conditional_t<__is_final(_Tp), false_type,\n \t\t      __is_empty_non_tuple<_Tp>>;\n+#else\n+  // For the unstable ABI we always use [[no_unique_address]].\n+  template<typename>\n+    using __empty_not_final = true_type;\n+#endif\n \n   template<size_t _Idx, typename _Head,\n \t   bool = __empty_not_final<_Head>::value>\n     struct _Head_base;\n \n-#if __has_cpp_attribute(__no_unique_address__)\n   template<size_t _Idx, typename _Head>\n     struct _Head_base<_Idx, _Head, true>\n     {\n@@ -141,61 +150,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \n       [[__no_unique_address__]] _Head _M_head_impl;\n     };\n-#else\n-  template<size_t _Idx, typename _Head>\n-    struct _Head_base<_Idx, _Head, true>\n-    : public _Head\n-    {\n-      constexpr _Head_base()\n-      : _Head() { }\n-\n-      constexpr _Head_base(const _Head& __h)\n-      : _Head(__h) { }\n-\n-      constexpr _Head_base(const _Head_base&) = default;\n-      constexpr _Head_base(_Head_base&&) = default;\n-\n-      template<typename _UHead>\n-        constexpr _Head_base(_UHead&& __h)\n-\t: _Head(std::forward<_UHead>(__h)) { }\n-\n-      _GLIBCXX20_CONSTEXPR\n-      _Head_base(allocator_arg_t, __uses_alloc0)\n-      : _Head() { }\n-\n-      template<typename _Alloc>\n-\t_GLIBCXX20_CONSTEXPR\n-\t_Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)\n-\t: _Head(allocator_arg, *__a._M_a) { }\n-\n-      template<typename _Alloc>\n-\t_GLIBCXX20_CONSTEXPR\n-\t_Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)\n-\t: _Head(*__a._M_a) { }\n-\n-      template<typename _UHead>\n-\t_GLIBCXX20_CONSTEXPR\n-\t_Head_base(__uses_alloc0, _UHead&& __uhead)\n-\t: _Head(std::forward<_UHead>(__uhead)) { }\n-\n-      template<typename _Alloc, typename _UHead>\n-\t_GLIBCXX20_CONSTEXPR\n-\t_Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)\n-\t: _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }\n-\n-      template<typename _Alloc, typename _UHead>\n-\t_GLIBCXX20_CONSTEXPR\n-\t_Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)\n-\t: _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }\n-\n-      static constexpr _Head&\n-      _M_head(_Head_base& __b) noexcept { return __b; }\n-\n-      static constexpr const _Head&\n-      _M_head(const _Head_base& __b) noexcept { return __b; }\n-    };\n-#endif\n \n+#if ! _GLIBCXX_INLINE_VERSION\n   template<size_t _Idx, typename _Head>\n     struct _Head_base<_Idx, _Head, false>\n     {\n@@ -250,6 +206,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \n       _Head _M_head_impl;\n     };\n+#endif\n \n #if __cpp_lib_tuple_like // >= C++23\n   struct __tuple_like_tag_t { explicit __tuple_like_tag_t() = default; };\n","prefixes":["v2","1/3"]}