[libcxx-commits] [libcxx] [libc++] Destroy elements when exceptions are thrown in __construct_at_end (PR #167112)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Nov 15 20:36:04 PST 2025
================
@@ -142,6 +143,20 @@ uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) {
return std::__uninitialized_fill_n<_ValueType>(__first, __n, __x);
}
+// uninitialized_default_construct_n
+
+template <class _ValueType, class _ForwardIterator, class _Size>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
+__uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
+ auto __idx = __first;
+ auto __guard = std::__make_exception_guard([&] { std::__destroy(__first, __idx); });
+ for (; __n > 0; ++__idx, (void)--__n)
+ std::__construct_at(std::addressof(*__idx));
----------------
frederick-vs-ja wrote:
This is wrong. The function name contains `default_construct` and it intentionally performed default-initialization, but you changed it to perform value-initialization.
https://github.com/llvm/llvm-project/pull/167112
More information about the libcxx-commits
mailing list