From patchwork Wed Sep 14 18:23:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp845769dyb; Wed, 14 Sep 2022 11:25:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR48Fkd72q4phcE1IYkFF6m0TtjZ6TWSiO7Ilo6n1ndxScsbSwh1YVJk/JZcrcK1uhavBrE3 X-Received: by 2002:a17:907:2e01:b0:77e:d84d:9e07 with SMTP id ig1-20020a1709072e0100b0077ed84d9e07mr9842376ejc.674.1663179959288; Wed, 14 Sep 2022 11:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663179959; cv=none; d=google.com; s=arc-20160816; b=Fq6xuVK5P56lWzaooLljIEnIsN73obHyojfP8FqQVsGa01/XFKArDBQeYY9kzH7zPo J3sdZfytCRbut2YYDz8V54xGDjSAyKTNBsB4trjBr6gY95tx4xNQaXgrdFaYz9HX/oyT lEghh8ShsDrJ5mUBg1dW9VgxNMvm4gGASHYgvhWYX/h6mX7SW9iKxYarwSTo3MOR+G6H yttaJ4ZkvYGCL2c+Va4f8M2pm7cwBUnFHioYimN8JaEK+wSFpCGP1ERm+pKTgBtyXV7B zoRTEJ/Xu5pZ3e4pBPRy4l3EHzlzSkmXatdp/XE5AUzj1HJphKNJKYJYcRvnzR8aa5SI 5KBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=96fsY2VK1AMqnCmZmASAtHLxfU+A9HMpECb8yR0S8hs=; b=UfDaFj80FBiPwonzEVLMF3+cIKbbY1iFFSSVtiLFxjyoK6OBKcUzfIdClbjzpbPzni oVFaiTsqWX385LZlF7v2SPhp5v1G031qvK52hK6epZlwDStmiqq5w1x956zcV6cRbzYQ ZACcuBsgRpVmg10+G62mUuH+f+HNavJ5WMUR3+0CVWgZLL8nDOB8oBc56NfbIFnUAVzc hAw5BUjxgQCFKPFA9ANRg0GpH5ZSDqd6VaN9uwK5/5tjrsfAm/ewm+lC4yIma6viZ4MU zRo6E1YxriIEFsyNd3T7qLnO3KeU61XcTd4DiUmyZDytdnfXPnW75oCDNGWs0LVjncFJ VCag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hk29xJfx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dd18-20020a170906c83200b0077081057215si11130845ejb.956.2022.09.14.11.25.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 11:25:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hk29xJfx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1AD9B3885515 for ; Wed, 14 Sep 2022 18:24:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AD9B3885515 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663179898; bh=96fsY2VK1AMqnCmZmASAtHLxfU+A9HMpECb8yR0S8hs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Hk29xJfxvotPV0rpwqSeniEfWxnvD3T2z/KjRcY7cOHbyn5HHEuA30h7hVXRHlQU7 odYOXQqnImgdxEROAnbOkczXtjvAw3SkaQ5A/kBx1uhwKGdRbmbEU3g25W1tkKFS/g AmgERpk5KqdKi091CtyPQcgTKEqowD74xpM+Ngt4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 50622384D160 for ; Wed, 14 Sep 2022 18:23:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 50622384D160 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) 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 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743970588597295237?= X-GMAIL-MSGID: =?utf-8?q?1743970588597295237?= 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(); +}