[libcxx-commits] [libcxx] [libc++] P2747R2: `constexpr` placement new (library part) (PR #105768)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 27 23:15:32 PDT 2024


================
@@ -15,19 +15,30 @@
 
 int A_constructed = 0;
 
-struct A
-{
-    A() {++A_constructed;}
-    ~A() {--A_constructed;}
+struct A {
+  A() { ++A_constructed; }
+  ~A() { --A_constructed; }
 };
 
-int main(int, char**)
-{
-    char buf[sizeof(A)];
+TEST_CONSTEXPR_OPERATOR_NEW void test_direct_call() {
+  assert(::operator new(sizeof(int), &A_constructed) == &A_constructed);
----------------
frederick-vs-ja wrote:

> Any reason you used `sizeof(int)`?

The reason is that this line (ditto in `new_array.pass.cpp`) tested taking address of the global variable (of static storage duration) `A_constructed` whose type is `int`, not any `A` object.


https://github.com/llvm/llvm-project/pull/105768


More information about the libcxx-commits mailing list