[libcxx-commits] [libcxx] [libc++] Add exception guard for vector<bool>::__init_with_sentinel (PR #115491)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 8 06:42:58 PST 2024
https://github.com/winner245 created https://github.com/llvm/llvm-project/pull/115491
I think this was missing from earlier PRs.
>From 4e057c1b49b847a16bd3513e1d2e950ab6aee04d Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Fri, 8 Nov 2024 00:23:42 -0500
Subject: [PATCH] Add exception guard for vector<bool>::__init_with_sentinel
---
libcxx/include/__vector/vector_bool.h | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 462095fd07acf7..4612cb96e67659 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -398,18 +398,12 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
template <class _InputIterator, class _Sentinel>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
__init_with_sentinel(_InputIterator __first, _Sentinel __last) {
-#if _LIBCPP_HAS_EXCEPTIONS
- try {
-#endif // _LIBCPP_HAS_EXCEPTIONS
- for (; __first != __last; ++__first)
- push_back(*__first);
-#if _LIBCPP_HAS_EXCEPTIONS
- } catch (...) {
- if (__begin_ != nullptr)
- __storage_traits::deallocate(__alloc(), __begin_, __cap());
- throw;
- }
-#endif // _LIBCPP_HAS_EXCEPTIONS
+ auto __guard = std::__make_exception_guard(__destroy_vector(*this));
+
+ for (; __first != __last; ++__first)
+ push_back(*__first);
+
+ __guard.__complete();
}
template <class _Iterator, class _Sentinel>
More information about the libcxx-commits
mailing list