[libcxx-commits] [libcxx] throw future_error in future.get() (PR #179409)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 2 23:54:37 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Ekkoruse (Ekkorus101)
<details>
<summary>Changes</summary>
fix segfault when we call future.get() twice, it's future_error in libstdc++ and recommended throw future_error in cppref
https://en.cppreference.com/w/cpp/thread/future/get.html
<img width="815" height="90" alt="image" src="https://github.com/user-attachments/assets/c201bb60-e3b4-4080-bba2-ffda8bab514d" />
---
Full diff: https://github.com/llvm/llvm-project/pull/179409.diff
1 Files Affected:
- (modified) libcxx/include/future (+3)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/179409
More information about the libcxx-commits
mailing list