Skip to content

Commit db02531

Browse files
committed
Add exception guard for constructor vector(n, x, a)
1 parent f147437 commit db02531

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

libcxx/include/__vector/vector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ class _LIBCPP_TEMPLATE_VIS vector {
165165
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
166166
vector(size_type __n, const value_type& __x, const allocator_type& __a)
167167
: __alloc_(__a) {
168+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
168169
if (__n > 0) {
169170
__vallocate(__n);
170171
__construct_at_end(__n, __x);
171172
}
173+
__guard.__complete();
172174
}
173175

174176
template <class _InputIterator,

0 commit comments

Comments
 (0)