[libcxx-commits] [libcxx] Add exception guard for constructor vector(n, x, a) (PR #113086)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 20 07:09:03 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: None (winner245)
<details>
<summary>Changes</summary>
Added exception guard to the `vector(n, x, a)` constructor to enhance exception safety. This change ensures that the `vector(n, x, a)` constructor is consistent with other constructors, such as `vector(n)`, `vector(n, x)`, `vector(n, a)`, in terms of exception safety.
---
Full diff: https://github.com/llvm/llvm-project/pull/113086.diff
1 Files Affected:
- (modified) libcxx/include/vector (+2)
``````````diff
diff --git a/libcxx/include/vector b/libcxx/include/vector
index dc31f31838264c..700cb51f41eeb2 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -487,10 +487,12 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
vector(size_type __n, const value_type& __x, const allocator_type& __a)
: __alloc_(__a) {
+ auto __guard = std::__make_exception_guard(__destroy_vector(*this));
if (__n > 0) {
__vallocate(__n);
__construct_at_end(__n, __x);
}
+ __guard.__complete();
}
template <class _InputIterator,
``````````
</details>
https://github.com/llvm/llvm-project/pull/113086
More information about the libcxx-commits
mailing list