[libcxx-commits] [PATCH] D94544: [libc++] NFCI: Refactor allocator_traits

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 18 14:36:59 PST 2021


ldionne accepted this revision as: libc++.
ldionne marked an inline comment as done.
ldionne added a comment.
This revision is now accepted and ready to land.

Thanks for the review Zoe!



================
Comment at: libcxx/include/__memory/allocator_traits.h:296
+    static void construct(allocator_type&, _Tp* __p, _Args&&... __args) {
 #if _LIBCPP_STD_VER > 17
+        _VSTD::construct_at(__p, _VSTD::forward<_Args>(__args)...);
----------------
zoecarver wrote:
> ldionne wrote:
> > zoecarver wrote:
> > > I don't really understand why we have two implementations here. This isn't a constexpr context, so they both do the same thing.
> > `construct_at` isn't provided before C++20.
> I was thinking the opposite: always construct with placement new. Is there a way (that isn't UB) for a user to know the difference?
> 
> (This is also a super small thing, no need to address it, I know this is a bit out-of-scope.)
The issue is that placement-new doesn't work inside `constexpr`, but `construct_at` does. This function is marked as `constexpr` in C++20 and above (`_LIBCPP_CONSTEXPR_AFTER_CXX17`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94544



More information about the libcxx-commits mailing list