From patchwork Mon Apr 18 14:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1618410 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=OvCZsQlf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4Khpb66LKDz9sG4 for ; Tue, 19 Apr 2022 00:04:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9C9F385840C for ; Mon, 18 Apr 2022 14:04:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9C9F385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650290671; bh=JmMHvz0BrHMoolp70T3uBTB/35WoTiecE2yQdkwiXhw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=OvCZsQlfTTFkR3Mb75OvkNgkV7swsPdwoeBYcKZUmOGkFZx0oo4Bp/TPP23dKDkt9 8x4fmSPlR/QuDVJDLKCBG/90JEdrAmhxEFtug+H95p7jjcrC6IY0FAdJP4tEp73zoe l6jgFrEnPFD1JW7il6zEvvH7kKgIoN2JWHJpAFG8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 47ED03858D28 for ; Mon, 18 Apr 2022 14:03:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 47ED03858D28 Received: by mail-wr1-x431.google.com with SMTP id x18so10839009wrc.0 for ; Mon, 18 Apr 2022 07:03:50 -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=JmMHvz0BrHMoolp70T3uBTB/35WoTiecE2yQdkwiXhw=; b=VsD1aJ0LhlI/9C465V7ASSxYj1TvNUdoda47d/GhJKlCt7bLSrtXokKhIuhSgJVR64 6mbKWaU97TBzN4h8ImS//fT1sQqHoB4egfErtETFTNnz+4tSiQntD3VR/SBBQLJG3nVc sSau5Xyy9QXp42NtX//YihX+zrzohqCXCcJ8FmzdgKPtJdUOs93juRkolLbqRMuh/+i4 RieUHBrVbFmAOJZ0YWNomCtD8Uyqq4SUDEisIpU4tmpRyxTMTer7IB1b/q3I7Zy0vMOj Ng9U3SGOAmNEpuyp8gaKb5OC5qsUJo4WPkCbKj5TTMhJHzRkEXaiSyeQYU53Q5TaLFrh PIKA== X-Gm-Message-State: AOAM531WUgKj8DRx37KTZRmcvZ4EfSc3KlK9e7SGSY6YhwRTmeXW3PHb Dl7Ky19MT3LhhDqTPSrU/umu2Pavafg= X-Google-Smtp-Source: ABdhPJwz4HDDZdImZglj2XJ2vC/ekE8uifnq2+m8tm2+BTXNAkhdVdf92sitaOQB0+lioJKmURsvjw== X-Received: by 2002:a05:6000:12cd:b0:207:a359:bd77 with SMTP id l13-20020a05600012cd00b00207a359bd77mr8585114wrx.552.1650290629040; Mon, 18 Apr 2022 07:03:49 -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 s7-20020a5d4247000000b00207a281b2f4sm9848545wrr.110.2022.04.18.07.03.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Apr 2022 07:03:48 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, coroutines: Account for overloaded promise return_value() [PR105301]. Date: Mon, 18 Apr 2022 15:03:42 +0100 Message-Id: <20220418140342.25820-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.3 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, T_SCC_BODY_TEXT_LINE 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" Whether it was intended or not, it is possible to define a coroutine promise with multiple return_value() methods [which need not even have the same type]. We were not accounting for this possibility in the check to see whether both return_value and return_void are specifier (which is prohibited by the standard). Fixed thus and provided an adjusted diagnostic for the case that multiple return_value() methods are present. tested on x86_64-darwin, OK for mainline? / Backports? (when?) thanks, Iain Signed-off-by: Iain Sandoe PR c++/105301 gcc/cp/ChangeLog: * coroutines.cc (coro_promise_type_found_p): Account for possible mutliple overloads of the promise return_value() method. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr105301.C: New test. --- gcc/cp/coroutines.cc | 10 ++++- gcc/testsuite/g++.dg/coroutines/pr105301.C | 49 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr105301.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index dcc2284171b..d2a765cac11 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -513,8 +513,14 @@ coro_promise_type_found_p (tree fndecl, location_t loc) coro_info->promise_type); inform (DECL_SOURCE_LOCATION (BASELINK_FUNCTIONS (has_ret_void)), "% declared here"); - inform (DECL_SOURCE_LOCATION (BASELINK_FUNCTIONS (has_ret_val)), - "% declared here"); + has_ret_val = BASELINK_FUNCTIONS (has_ret_val); + const char *message = "% declared here"; + if (TREE_CODE (has_ret_val) == OVERLOAD) + { + has_ret_val = OVL_FIRST (has_ret_val); + message = "% first declared here"; + } + inform (DECL_SOURCE_LOCATION (has_ret_val), message); coro_info->coro_co_return_error_emitted = true; return false; } diff --git a/gcc/testsuite/g++.dg/coroutines/pr105301.C b/gcc/testsuite/g++.dg/coroutines/pr105301.C new file mode 100644 index 00000000000..33a0b03cf5d --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr105301.C @@ -0,0 +1,49 @@ +// { dg-additional-options "-fsyntax-only" } +namespace std { +template +struct traits_sfinae_base {}; + +template +struct coroutine_traits : public traits_sfinae_base {}; +} + +template struct coro {}; +template +struct std::coroutine_traits, Ps...> { + using promise_type = Promise; +}; + +struct awaitable { + bool await_ready() noexcept; + template + void await_suspend(F) noexcept; + void await_resume() noexcept; +} a; + +struct suspend_always { + bool await_ready() noexcept { return false; } + template + void await_suspend(F) noexcept; + void await_resume() noexcept {} +}; + +namespace std { +template +struct coroutine_handle {}; +} + +struct bad_promise_6 { + coro get_return_object(); + suspend_always initial_suspend(); + suspend_always final_suspend() noexcept; + void unhandled_exception(); + void return_void(); + void return_value(int) const; + void return_value(int); +}; + +coro +bad_implicit_return() // { dg-error {.aka 'bad_promise_6'. declares both 'return_value' and 'return_void'} } +{ + co_await a; +}