Skip to content

Commit e55a7a1

Browse files
committed
Add exception guard for vector<bool>::__init_with_sentinel
1 parent d7ab5da commit e55a7a1

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
@@ -390,18 +390,12 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
390390
template <class _InputIterator, class _Sentinel>
391391
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
392392
__init_with_sentinel(_InputIterator __first, _Sentinel __last) {
393-
#if _LIBCPP_HAS_EXCEPTIONS
394-
try {
395-
#endif // _LIBCPP_HAS_EXCEPTIONS
396-
for (; __first != __last; ++__first)
397-
push_back(*__first);
398-
#if _LIBCPP_HAS_EXCEPTIONS
399-
} catch (...) {
400-
if (__begin_ != nullptr)
401-
__storage_traits::deallocate(__alloc_, __begin_, __cap_);
402-
throw;
403-
}
404-
#endif // _LIBCPP_HAS_EXCEPTIONS
393+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
394+
395+
for (; __first != __last; ++__first)
396+
push_back(*__first);
397+
398+
__guard.__complete();
405399
}
406400

407401
template <class _Iterator, class _Sentinel>

0 commit comments

Comments
 (0)