[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 15:46:56 PDT 2022
philnik accepted this revision.
philnik added a comment.
LGTM with the alignment bug fixed.
================
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;
----------------
You could instead do
```lang=c++
union { P p; };
a.construct(&p);
```
That would fix the alignment bug and avoid a `reinterpret_cast`.
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