diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h index 7889e8c2201ac..844e5d6a21056 100644 --- a/libcxx/include/__vector/vector.h +++ b/libcxx/include/__vector/vector.h @@ -165,10 +165,12 @@ class _LIBCPP_TEMPLATE_VIS vector { _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x, const allocator_type& __a) : __alloc_(__a) { + auto __guard = std::__make_exception_guard(__destroy_vector(*this)); if (__n > 0) { __vallocate(__n); __construct_at_end(__n, __x); } + __guard.__complete(); } template = 14 + try { // Throw in vector(size_type, value_type, const allocator_type&) from the type + int throw_after = 1; + ThrowingT v(throw_after); + std::vector vec(1, v, std::allocator()); + } catch (int) { + } + check_new_delete_called(); + try { // Throw in vector(InputIterator, InputIterator) from input iterator std::vector vec((Iterator()), Iterator(2)); } catch (int) {