From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add assertion to std::promise::set_exception (LWG 2276)
Date: Wed, 14 Sep 2022 19:23:29 +0100 [thread overview]
Message-ID: <20220914182329.263649-1-jwakely@redhat.com> (raw)
Tested x86_64-linux, pushed to trunk.
-- >8 --
Without this assertion, the shared state is made ready, but contains
neither a value nor an exception. Add an assertion to prevent users from
accessing a value that was never initialized in the shared state.
libstdc++-v3/ChangeLog:
* include/std/future
(_State_baseV2::__setter(exception_ptr&, promise&)): Add
assertion for LWG 2276 precondition.
* testsuite/30_threads/promise/members/set_exception_neg.cc:
New test.
---
libstdc++-v3/include/std/future | 1 +
.../promise/members/set_exception_neg.cc | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 libstdc++-v3/testsuite/30_threads/promise/members/set_exception_neg.cc
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index ba1f28c6c75..a1b2d7f1d3a 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -559,6 +559,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static _Setter<_Res, __exception_ptr_tag>
__setter(exception_ptr& __ex, promise<_Res>* __prom) noexcept
{
+ __glibcxx_assert(__ex != nullptr); // LWG 2276
return _Setter<_Res, __exception_ptr_tag>{ __prom, &__ex };
}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception_neg.cc
new file mode 100644
index 00000000000..16660931242
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception_neg.cc
@@ -0,0 +1,18 @@
+// { dg-options "-D_GLIBCXX_ASSERTIONS" }
+// { dg-do run { xfail *-*-* } }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-require-effective-target c++11 }
+// { dg-require-gthreads "" }
+
+// LWG 2276. Missing requirement on std::promise::set_exception
+
+#include <future>
+
+int main()
+{
+ std::promise<void> prom;
+ auto f = prom.get_future();
+ std::exception_ptr p;
+ prom.set_exception(p); // Preconditions: p is not null
+ f.get();
+}
--
2.37.3
reply other threads:[~2022-09-14 18:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220914182329.263649-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).