[libcxx-commits] [libcxx] Replace ::new with construct_at in allocator. (PR #105593)

Amy Huang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 21 16:36:46 PDT 2024


https://github.com/amykhuang updated https://github.com/llvm/llvm-project/pull/105593

>From ebdd4d2845f8cccdc0fe0e99d2c7d257dec468eb Mon Sep 17 00:00:00 2001
From: Amy Huang <akhuang at google.com>
Date: Tue, 20 Aug 2024 22:34:01 +0000
Subject: [PATCH] Correct allocator default behavior.

---
 libcxx/docs/Status/Cxx20Issues.csv  | 1 +
 libcxx/include/__memory/allocator.h | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv
index 1d441de31f107b..a71ea2604d2e21 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -1,4 +1,5 @@
 "Issue #","Issue Name","Meeting","Status","First released version","Labels"
+"`LWG3315 <https://wg21.link/LWG3315>`__","``a.construct``\ should call ``construct_at``\","2020-02 (Prague)","|Complete|","",""
 "`LWG2070 <https://wg21.link/LWG2070>`__","``allocate_shared``\  should use ``allocator_traits<A>::construct``\ ","2017-07 (Toronto)","Resolved by `P0674R1 <https://wg21.link/P0674R1>`__","",""
 "`LWG2444 <https://wg21.link/LWG2444>`__","Inconsistent complexity for ``std::sort_heap``\ ","2017-07 (Toronto)","|Nothing To Do|","",""
 "`LWG2593 <https://wg21.link/LWG2593>`__","Moved-from state of Allocators","2017-07 (Toronto)","","",""
diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index 0dbdc41d3c3d14..937b1f06c7785e 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -148,10 +148,12 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::v
 
   template <class _Up, class... _Args>
   _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) {
-    ::new ((void*)__p) _Up(std::forward<_Args>(__args)...);
+    std::construct_at(__p, std::forward<Args>(args)...);
   }
 
-  _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); }
+  _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) {
+    std::destroy_at(__p);
+  }
 #endif
 };
 



More information about the libcxx-commits mailing list