From patchwork Sun Oct 3 19:56:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1535877 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jst1eV1Y; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HMvkk6bSbz9sRK for ; Mon, 4 Oct 2021 06:57:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D2013857006 for ; Sun, 3 Oct 2021 19:57:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D2013857006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633291020; bh=HAjw0wTSxL0YrH57GhGzkfHZZd6zjwwRAkYzQXYRon4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jst1eV1Y9pL2Z9boNKguGVb5N4MeOJ9rFkn7rxGluLJ/bomaQDunu7mpEu5HsVieF Em6IK92QmZYM+l3GdwnGjZSzAJsovJ0l8VIxzdsuovnsdCNIpwkraZRg6FRy9HUWvR 3YRzflmHltakvhiTqWaWmxcpf8T/YVPbbx5C0/ZM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id B58A93858D39 for ; Sun, 3 Oct 2021 19:56:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B58A93858D39 Received: by mail-wm1-x32b.google.com with SMTP id s24so11695978wmh.4 for ; Sun, 03 Oct 2021 12:56:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=HAjw0wTSxL0YrH57GhGzkfHZZd6zjwwRAkYzQXYRon4=; b=UMpZifpwXy7XYHmndBOT9xX3coaTh58gy6gaFANbT/L1Tmy4yY4k7sZrVPgeQVVCi6 pfTkbyD43Yk+gu661cCyI/pItYOdSPsCPjU2R1T68CrG4gWxP66xJUK/Wc5alSlMdeAm /dz5JmwMwmvqjjEKZfSVBXnK7aaU29H4HXTX0BxfT4UuT8wRMTrxWYAx9Y7wAMghj9zn 66CS65+Y63en+4Xehia2YcFC6FIYYF9hjJlxzLleRgiIMY9Q+1uyLVl+jfglaIRSsweK QK3tg201qcX0oHJmhsg/RGORFrSnhsvEWPCsjYGjVoe6SsC2LIHoWcHSVg6yinQRU+qv BsPA== X-Gm-Message-State: AOAM531iiwjalBFwtc/yaM5yfc2U82pdj8Oh0sWitPgaBNRBv1zzQ1Jn 1z9F2pHwXiS6SRuZPsDNSxkhowISlK2/hw== X-Google-Smtp-Source: ABdhPJzaZvjDx1A919U0S9wTs8SOjTB28063AI5PlBIydB3He51ZJJqtIpEs9RYrZ4FXyMl1ULICQA== X-Received: by 2002:a05:600c:240a:: with SMTP id 10mr15071180wmp.170.1633290996817; Sun, 03 Oct 2021 12:56:36 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id z133sm16699228wmc.45.2021.10.03.12.56.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Oct 2021 12:56:36 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] coroutines: Await expressions are not allowed in handlers [PR 99710]. Date: Sun, 3 Oct 2021 20:56:30 +0100 Message-Id: <20211003195630.67604-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, C++20 [expr.await] / 2 An await-expression shall appear only in a potentially-evaluated expression within the compound-statement of a function-body outside of a handler. tested on x86_64, powerpc64le-linux, x86_64-darwin, cppcoro and folly, pushed to master as obvious, thanks Iain Signed-off-by: Iain Sandoe PR c++/99710 gcc/cp/ChangeLog: * coroutines.cc (await_statement_walker): Report an error if an await expression is found in a handler body. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr99710.C: New test. --- gcc/cp/coroutines.cc | 17 ++++++++++++++- gcc/testsuite/g++.dg/coroutines/pr99710.C | 25 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr99710.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 1dd9abd1e1f..377b90c777f 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -3688,7 +3688,22 @@ await_statement_walker (tree *stmt, int *do_subtree, void *d) *do_subtree = 0; return res; } - break; + break; + case HANDLER: + { + /* [expr.await] An await-expression shall appear only in a + potentially-evaluated expression within the compound-statement + of a function-body outside of a handler. */ + tree *await_ptr; + hash_set visited; + if (!(cp_walk_tree (&HANDLER_BODY (expr), find_any_await, + &await_ptr, &visited))) + return NULL_TREE; /* All OK. */ + location_t loc = EXPR_LOCATION (*await_ptr); + error_at (loc, "await expressions are not permitted in handlers"); + return NULL_TREE; /* This is going to fail later anyway. */ + } + break; } else if (EXPR_P (expr)) { diff --git a/gcc/testsuite/g++.dg/coroutines/pr99710.C b/gcc/testsuite/g++.dg/coroutines/pr99710.C new file mode 100644 index 00000000000..e4f7116b8d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr99710.C @@ -0,0 +1,25 @@ +#include + +struct task { + struct promise_type { + std::suspend_always initial_suspend(); + std::suspend_always final_suspend() noexcept; + task get_return_object(); + void return_void(); + void unhandled_exception(); + }; +}; + +task +my_coro () +{ + try + { } + catch (...) + { + // [expr.await] An await-expression shall appear only in a potentially- + // evaluated expression within the compound-statement of a function-body + // outside of a handler + co_await std::suspend_always{}; // { dg-error "await expressions are not permitted in handlers" } + } +}