[libcxx-commits] [libcxx] [libc++] Throw future_error in future.get() (PR #179409)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 6 10:06:33 PST 2026


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/179409

>From 179c9d396e43f3c1daf5d0730e4a8b5b7fb7c390 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..472aa7f9adefb 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(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