[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


================
@@ -949,10 +954,7 @@ template <class _Tp, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
   _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), __x);
-  }
+  __tx.__pos_ = std::__uninitialized_fill_n_with_alloc<_Allocator>(this->__alloc_, this->__end_, __n, __x);
----------------
frederick-vs-ja wrote:

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

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


More information about the libcxx-commits mailing list