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

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 26 11:47:07 PST 2023


Author: philnik777
Date: 2023-11-26T20:47:03+01:00
New Revision: cd9829c231e32dc73cfe1957f84b1645e9105196

URL: https://github.com/llvm/llvm-project/commit/cd9829c231e32dc73cfe1957f84b1645e9105196
DIFF: https://github.com/llvm/llvm-project/commit/cd9829c231e32dc73cfe1957f84b1645e9105196.diff

LOG: [libc++][NFC] Use __construct_at and __destroy_at instead of using preprocessor conditionals (#70866)

Added: 
    

Modified: 
    libcxx/include/__memory/allocator_traits.h
    libcxx/include/optional
    libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp
    libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.verify.cpp

Removed: 
    


################################################################################
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..af8ca01370f0800 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-re@* {{{{(no matching function for call to '__construct_at')|(call to deleted constructor of 'MoveOnly')}}}}
 }

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