Skip to content

Commit f6d9ccc

Browse files
committed
Add exception guard for vector<bool>::__init_with_sentinel
1 parent 38a675a commit f6d9ccc

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

libcxx/include/__vector/vector_bool.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,12 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
398398
template <class _InputIterator, class _Sentinel>
399399
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
400400
__init_with_sentinel(_InputIterator __first, _Sentinel __last) {
401-
#if _LIBCPP_HAS_EXCEPTIONS
402-
try {
403-
#endif // _LIBCPP_HAS_EXCEPTIONS
404-
for (; __first != __last; ++__first)
405-
push_back(*__first);
406-
#if _LIBCPP_HAS_EXCEPTIONS
407-
} catch (...) {
408-
if (__begin_ != nullptr)
409-
__storage_traits::deallocate(__alloc(), __begin_, __cap());
410-
throw;
411-
}
412-
#endif // _LIBCPP_HAS_EXCEPTIONS
401+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
402+
403+
for (; __first != __last; ++__first)
404+
push_back(*__first);
405+
406+
__guard.__complete();
413407
}
414408

415409
template <class _Iterator, class _Sentinel>

0 commit comments

Comments
 (0)