[libcxx-commits] [PATCH] D91201: [libc++] LWG2070: Use Allocator construction for objects created with allocate_shared

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 14 15:52:15 PST 2020


ldionne added a comment.

Another approach, which Zoe thought about just now and told me on Slack, would be to implement the storage like this instead (untested, I just wrote this up):

  struct _Storage {
      _LIBCPP_HIDE_FROM_ABI explicit _Storage(_Alloc&& __a) {
          ::new ((void*)__get_alloc()) _Alloc(_VSTD::move(__a));
      }
      _LIBCPP_HIDE_FROM_ABI ~_Storage() {
          __get_alloc()->~_Alloc();
      }
      _Alloc* __get_alloc() _NOEXCEPT { /* compute offset */ }
      _Tp* __get_elem() _NOEXCEPT { /* compute offset */ }
      char alignas(__compressed_pair<_Alloc, _Tp>) __blob_[sizeof(__compressed_pair<_Alloc, _Tp>)];
  };

I think we'd be able to compute the offsets with a bit of help from the `__compressed_pair`, and then I'm pretty sure it would be valid to placement-new into the blob as we like. I'll explore this approach too to see what it gives - the benefit would be not needing `[[no_unique_address]]` and potentially simpler code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91201



More information about the libcxx-commits mailing list