[libcxx-commits] [PATCH] D102135: [libcxx][ranges] adds _`copyable-box`_

Tim Song via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 6 11:54:28 PDT 2021


tcanens added inline comments.


================
Comment at: libcxx/include/__ranges/copyable_box.h:47
+  class __copyable_box {
+    optional<_Tp> __val_;
+
----------------
ldionne wrote:
> Quuxplusone wrote:
> > ldionne wrote:
> > > cjdb wrote:
> > > > Can this be `[[no_unique_address]]`?
> > > There's really no point in doing that AFAICT, because `std::optional` is never empty.
> > `[[no_unique_address]]` also has a layout effect on non-empty types, if they're tail-padded: https://godbolt.org/z/qjMWo699x
> > 
> > However, AIUI, its effect never leaks out of a type altogether: it makes a difference //only// on a member of `X` that is directly followed by another member of `X`. So if you have a class with only one data member, like this version of `__copyable_box`, then adding `[[no_unique_address]]` to that unique data member will never make a difference. (I think.) https://godbolt.org/z/K3GPPaxbz
> That matches my understanding too. I don't think it's possible for the effect to leak out of the type since it must be possible to lay out objects of that type one after another in an array without messing up their alignment.
Not quite: https://godbolt.org/z/Yhs6MqzYn


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102135/new/

https://reviews.llvm.org/D102135



More information about the libcxx-commits mailing list