[libcxx-commits] [libcxx] throw future_error in future.get() (PR #179409)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 2 23:59:52 PST 2026
https://github.com/Ekkorus101 updated https://github.com/llvm/llvm-project/pull/179409
>From 0d695cfe9ad2a4e2bbcce4ff37658c41ec5d7b3f Mon Sep 17 00:00:00 2001
From: zhangqingchun <zhangqingchun at bytedance.com>
Date: Tue, 3 Feb 2026 15:45:06 +0800
Subject: [PATCH] throw future_error in future.get()
fix segfault when we call future.get() twice, it's future_error in
libstdc++ and recommended throw future_error in cppref
---
libcxx/include/future | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libcxx/include/future b/libcxx/include/future
index 4084148e52af6..e25153eded4a9 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -985,6 +985,9 @@ future<_Rp>::~future() {
template <class _Rp>
_Rp future<_Rp>::get() {
+ if (__state_ == nullptr) [[unlikely]] {
+ throw future_error(make_error_code(future_errc::no_state));
+ }
unique_ptr<__shared_count, __release_shared_count> __guard(__state_);
__assoc_state<_Rp>* __s = __state_;
__state_ = nullptr;
More information about the libcxx-commits
mailing list