[libcxx-commits] [libcxx] [libc++] Add exception guard for vector<bool>::__init_with_sentinel (PR #115491)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 11 06:57:55 PST 2024
================
@@ -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));
----------------
ldionne wrote:
IIUC, this isn't fixing a bug, right? I think both versions are 100% equivalent.
If that's not the case, then what is the behaviour change? We should have a test for it.
https://github.com/llvm/llvm-project/pull/115491
More information about the libcxx-commits
mailing list