]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Allow adjacent __maybe_present_t<false, ...> fields to overlap
authorPatrick Palka <ppalka@redhat.com>
Tue, 2 Apr 2024 17:07:07 +0000 (13:07 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 2 Apr 2024 17:07:07 +0000 (13:07 -0400)
commit0e64bbb8823f7b3757befc878ed177dfb59943d1
tree1b7be5167af2481afc7f445b388ca4c42d959235
parentd5aa2ca06aa7a6a2f826c4da19204b6db1402995
libstdc++: Allow adjacent __maybe_present_t<false, ...> fields to overlap

Currently __maybe_present_t<false, T> maps to the same empty class
type independent of T.  This is suboptimal because it means adjacent
__maybe_present_t<false, ...> 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<false, T> _M_a;
  [[no_unique_address]] __maybe_present_t<false, U> _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<V> is 3 instead 4 pointers.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc
This page took 0.061425 seconds and 6 git commands to generate.