From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C95183850203 for ; Wed, 14 Sep 2022 18:23:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C95183850203 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663179812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=96fsY2VK1AMqnCmZmASAtHLxfU+A9HMpECb8yR0S8hs=; b=Ga6PXz3wOQCH6t0CL8M9kUAc6tJHhKdECb0t6oq1RH7mvVzwCgvAPuja5Flwof5IBi1ujY 04bDf90E9FL2eXpuab5nmJu3U/YGFeud70l8adwWf7ZL4/mS17CIFXmaktHu+9mngIKA1T sD/6RP6ViQKswBRA0QlfGvqfmbjfM4Y= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-VoDGams1OVGbn3mG0vIUCQ-1; Wed, 14 Sep 2022 14:23:31 -0400 X-MC-Unique: VoDGams1OVGbn3mG0vIUCQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A46B53C1104D; Wed, 14 Sep 2022 18:23:30 +0000 (UTC) Received: from localhost (unknown [10.33.36.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DB4CC15BA4; Wed, 14 Sep 2022 18:23:30 +0000 (UTC) From: Jonathan Wakely 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 Message-Id: <20220914182329.263649-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 + +int main() +{ + std::promise prom; + auto f = prom.get_future(); + std::exception_ptr p; + prom.set_exception(p); // Preconditions: p is not null + f.get(); +} -- 2.37.3