[libcxx-commits] [libcxx] [libc++][NFC] Use __construct_at and __destroy_at insted of using preprocessor conditionals (PR #70866)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 19 07:36:22 PST 2023


https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/70866

>From 3b8e283ca43f1903b97993e15046db8959a2d9e2 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 31 Oct 2023 23:14:10 +0100
Subject: [PATCH] [libc++][NFC] Use __construct_at and __destroy_at insted of
 using preprocessor conditionals

---
 libcxx/include/__memory/allocator_traits.h           | 12 ++----------
 libcxx/include/optional                              |  6 +-----
 .../vector/vector.cons/copy.move_only.verify.cpp     |  2 +-
 .../resize_not_move_insertable.verify.cpp            |  2 +-
 4 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/libcxx/include/__memory/allocator_traits.h b/libcxx/include/__memory/allocator_traits.h
index 157254619ebeda6..eea5ee973d37fd7 100644
--- a/libcxx/include/__memory/allocator_traits.h
+++ b/libcxx/include/__memory/allocator_traits.h
@@ -300,11 +300,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
         __enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
     static void construct(allocator_type&, _Tp* __p, _Args&&... __args) {
-#if _LIBCPP_STD_VER >= 20
-        _VSTD::construct_at(__p, _VSTD::forward<_Args>(__args)...);
-#else
-        ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
-#endif
+        std::__construct_at(__p, std::forward<_Args>(__args)...);
     }
 
     template <class _Tp, class =
@@ -319,11 +315,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
         __enable_if_t<!__has_destroy<allocator_type, _Tp*>::value> >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
     static void destroy(allocator_type&, _Tp* __p) {
-#if _LIBCPP_STD_VER >= 20
-        _VSTD::destroy_at(__p);
-#else
-        __p->~_Tp();
-#endif
+        std::__destroy_at(__p);
     }
 
     template <class _Ap = _Alloc, class =
diff --git a/libcxx/include/optional b/libcxx/include/optional
index ab90cc8ce7f776c..f627fe9a0d58aeb 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -416,11 +416,7 @@ struct __optional_storage_base : __optional_destruct_base<_Tp>
     _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct(_Args&&... __args)
     {
         _LIBCPP_ASSERT_INTERNAL(!has_value(), "__construct called for engaged __optional_storage");
-#if _LIBCPP_STD_VER >= 20
-        _VSTD::construct_at(_VSTD::addressof(this->__val_), _VSTD::forward<_Args>(__args)...);
-#else
-        ::new ((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...);
-#endif
+        std::__construct_at(std::addressof(this->__val_), std::forward<_Args>(__args)...);
         this->__engaged_ = true;
     }
 
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp
index f716eccf94e36b8..b6ab6a740d6f9d0 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp
@@ -16,5 +16,5 @@
 
 void f() {
     std::vector<MoveOnly> v;
-    std::vector<MoveOnly> copy = v; // expected-error-re@* {{{{(no matching function for call to 'construct_at')|(call to implicitly-deleted copy constructor of 'MoveOnly')|(call to deleted constructor of 'MoveOnly')}}}}
+    std::vector<MoveOnly> copy = v; // expected-error@* {{no matching function for call to '__construct_at'}}
 }
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.verify.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.verify.cpp
index 99f28ff4f27e867..8eb055283fdf4c8 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.verify.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.verify.cpp
@@ -33,7 +33,7 @@ int main(int, char**) {
 
   // Other diagnostics that might be seen as Clang tries to continue compiling:
   // expected-error@* 0-2 {{call to deleted constructor}}
-  // expected-error@* 0-2 {{no matching function for call to 'construct_at'}}
+  // expected-error@* 0-2 {{no matching function for call to '__construct_at'}}
   {
 
     std::vector<BadUserNoCookie<1> > x;



More information about the libcxx-commits mailing list