[libcxx-commits] [libcxx] [libc++][vector] Make constructor vector(count, value, allocator) exception-safe (PR #82033)

Mateusz Zych via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 16 15:45:36 PST 2024


https://github.com/mtezych updated https://github.com/llvm/llvm-project/pull/82033

>From 7ff58b52a916bf4c64be0be2e84dff11668d3de4 Mon Sep 17 00:00:00 2001
From: Mateusz Zych <mte.zych at gmail.com>
Date: Fri, 16 Feb 2024 23:35:10 +0300
Subject: [PATCH] [libc++][vector] Make constructor vector(count, value,
 allocator) exception-safe

---
 libcxx/include/vector | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libcxx/include/vector b/libcxx/include/vector
index ce7df7a9f04207..c3e3f05671f8fa 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -433,10 +433,12 @@ public:
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
   vector(size_type __n, const value_type& __x, const allocator_type& __a)
       : __end_cap_(nullptr, __a) {
+    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
     if (__n > 0) {
       __vallocate(__n);
       __construct_at_end(__n, __x);
     }
+    __guard.__complete();
   }
 
   template <class _InputIterator,



More information about the libcxx-commits mailing list