[libcxx-commits] [libcxx] [libc++] Destroy elements when exceptions are thrown in __construct_at_end (PR #167112)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 16 17:43:08 PST 2025


================
@@ -933,10 +941,7 @@ vector<_Tp, _Allocator>::__recommend(size_type __new_size) const {
 template <class _Tp, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) {
   _ConstructTransaction __tx(*this, __n);
-  const_pointer __new_end = __tx.__new_end_;
-  for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
-    __alloc_traits::construct(this->__alloc_, std::__to_address(__pos));
-  }
+  __tx.__pos_ = std::__uninitialized_default_construct_n_with_alloc<_Allocator>(this->__alloc_, this->__end_, __n);
----------------
frederick-vs-ja wrote:

```suggestion
  __tx.__pos_ = std::__uninitialized_allocator_value_construct_n<_Allocator>(this->__alloc_, this->__end_, __n);
```

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


More information about the libcxx-commits mailing list