From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id A32593858D28; Tue, 2 Apr 2024 17:07:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A32593858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712077678; bh=RpKVeOPFkVoeuaBzhCj9du8grKk52+/KYdaVOK6Hgwc=; h=From:To:Subject:Date:From; b=kSZw1MpcLOphuJONENK9+Pex2jOI1R3T5QEGe85sA3kPvzBgmw2Mc/g5XrTjpIe3Y +nWpg81D3J4UVpcMicTJ+XqQduXx390borWOg5QX/dLHsifujS1vX6Fkt71g2NXcCu qyF1t4EjdoRbpZE0W4QMo909ppfASiN37fPfundM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-9756] libstdc++: Allow adjacent __maybe_present_t fields to overlap X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: d5aa2ca06aa7a6a2f826c4da19204b6db1402995 X-Git-Newrev: 0e64bbb8823f7b3757befc878ed177dfb59943d1 Message-Id: <20240402170758.A32593858D28@sourceware.org> Date: Tue, 2 Apr 2024 17:07:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0e64bbb8823f7b3757befc878ed177dfb59943d1 commit r14-9756-g0e64bbb8823f7b3757befc878ed177dfb59943d1 Author: Patrick Palka Date: Tue Apr 2 13:07:07 2024 -0400 libstdc++: Allow adjacent __maybe_present_t fields to overlap Currently __maybe_present_t maps to the same empty class type independent of T. This is suboptimal because it means adjacent __maybe_present_t members with the [[no_unique_address]] attribute can't overlap even if the conditionally present types are different. This patch turns this empty class type into a template parameterized by the conditionally present type, so that [[no_unique_address]] __maybe_present_t _M_a; [[no_unique_address]] __maybe_present_t _M_b; now overlap if T and U are different. This patch goes a step further and also adds an optional integer discriminator parameter to allow for overlapping when T and U are the same. libstdc++-v3/ChangeLog: * include/std/ranges (ranges::__detail::_Empty): Rename to ... (ranges::__detail::_Absent): ... this. Turn into a template parameterized by the absent type _Tp and discriminator _Disc. (ranges::__detail::__maybe_present_t): Add an optional discriminator parameter. (slide_view::_M_cached_begin): Pass a discriminator argument to __maybe_present_t. (slide_view::_M_cached_end): Likewise. * testsuite/std/ranges/adaptors/sizeof.cc: Verify the size of slide_view is 3 instead 4 pointers. Reviewed-by: Jonathan Wakely Diff: --- libstdc++-v3/include/std/ranges | 13 ++++++++----- libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 7d739852677..afce818376b 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -886,14 +886,17 @@ namespace views namespace __detail { - struct _Empty { }; + template + struct _Absent { }; // Alias for a type that is conditionally present // (and is an empty type otherwise). // Data members using this alias should use [[no_unique_address]] so that // they take no space when not needed. - template - using __maybe_present_t = __conditional_t<_Present, _Tp, _Empty>; + // The optional template parameter _Disc is for discriminating two otherwise + // equivalent absent types so that even they can overlap. + template + using __maybe_present_t = __conditional_t<_Present, _Tp, _Absent<_Tp, _Disc>>; // Alias for a type that is conditionally const. template @@ -6553,10 +6556,10 @@ namespace views::__adaptor range_difference_t<_Vp> _M_n; [[no_unique_address]] __detail::__maybe_present_t<__detail::__slide_caches_first<_Vp>, - __detail::_CachedPosition<_Vp>> _M_cached_begin; + __detail::_CachedPosition<_Vp>, 0> _M_cached_begin; [[no_unique_address]] __detail::__maybe_present_t<__detail::__slide_caches_last<_Vp>, - __detail::_CachedPosition<_Vp>> _M_cached_end; + __detail::_CachedPosition<_Vp>, 1> _M_cached_end; template class _Iterator; class _Sentinel; diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc index 12a9da3181d..08c01704d10 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc @@ -49,3 +49,7 @@ static_assert(sizeof(ranges::lazy_split_view) == 4*ptr); static_assert (sizeof(ranges::reverse_view>) == 3*ptr); + +#if __cpp_lib_ranges_slide +static_assert(sizeof(ranges::slide_view) == 3*ptr); +#endif