Skip to content

Conversation

@Ekkorus101
Copy link

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

image

@Ekkorus101 Ekkorus101 requested a review from a team as a code owner February 3, 2026 07:53
@github-actions
Copy link

github-actions bot commented Feb 3, 2026

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 3, 2026
@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2026

@llvm/pr-subscribers-libcxx

Author: Ekkoruse (Ekkorus101)

Changes

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 --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;

fix segfault when we call future.get() twice, it's future_error in
libstdc++ and recommended throw future_error in cppref
@Ekkorus101 Ekkorus101 force-pushed the ekk_double_future_get_throw branch from fe34853 to 179c9d3 Compare February 3, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants