[libcxx-commits] [PATCH] D137188: [libc++] Use stack buffers for uninitialized storage in tests.

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 1 16:06:07 PDT 2022


philnik accepted this revision.
philnik added inline comments.


================
Comment at: libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/construct_pair.pass.cpp:40-41
     typedef std::pmr::polymorphic_allocator<void> A;
-    P* ptr = (P*)std::malloc(sizeof(P));
+    char buffer[sizeof(P)];
+    P* ptr = reinterpret_cast<P*>(buffer);
     A a;
----------------
var-const wrote:
> philnik wrote:
> > You could instead do
> > ```lang=c++
> > union { P p; };
> > a.construct(&p);
> > ```
> > That would fix the alignment bug and avoid a `reinterpret_cast`.
> That doesn't work because the default constructors in question are non-trivial. How about using `alignas` instead?
Ah, I missed that. Then `alignas` is probably the correct call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137188



More information about the libcxx-commits mailing list