[libcxx-commits] [libcxx] [libc++] Prevent std::terminate in promise<void> destructor race (PR #221258)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 18 01:42:30 PDT 2026
================
@@ -144,8 +145,12 @@ promise<void>::promise() : __state_(new __assoc_sub_state) {}
promise<void>::~promise() {
if (__state_) {
#if _LIBCPP_HAS_EXCEPTIONS
- if (!__state_->__has_value() && __state_->use_count() > 1)
- __state_->set_exception(make_exception_ptr(future_error(future_errc::broken_promise)));
+ if (!__state_->__has_value() && __state_->use_count() > 1) {
+ try {
+ __state_->set_exception(make_exception_ptr(future_error(future_errc::broken_promise)));
+ } catch (...) {
+ }
----------------
huixie90 wrote:
i am not sure about this. In case it does throw, this implementation will leave the shared state in an indeterministic state, whereas the standard requires it to store an `future_error`
https://eel.is/c++draft/futures.state#7.1.1
In that sense, I would argue `std::terminate` is better than a silent wrong answer
https://github.com/llvm/llvm-project/pull/221258
More information about the libcxx-commits
mailing list