[libcxx-commits] [PATCH] D137188: [libc++] Use stack buffers for uninitialized storage in tests.
Konstantin Varlamov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 1 16:04:00 PDT 2022
var-const marked an inline comment as done.
var-const 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;
----------------
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?
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