From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 658C73858D3C for ; Wed, 20 Apr 2022 07:13:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 658C73858D3C Received: by mail-ej1-x630.google.com with SMTP id u15so1553652ejf.11 for ; Wed, 20 Apr 2022 00:13:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ki8/XyNMbMDO9DZSGGeTG5LxRM9NHDVBdoyjVSTAubM=; b=kmU5Q4nToMehcednUdu0bkaW6z0qb5i74OmQmUztaYVuQ44aaKWo9oNyS2bE1d08EF k9DZi0g6HiZmvEy6ggkJ2VCGWiOieYPWN3qZP687Xa+MEVA4X69/qhSbgpVpHkpTLJuz KmXmOhAnoS68BjIfaeC6zTcyWyLR5Nn0jBcF2lSM+4rvcD0XTtSxGsw0iiNhE46lxC9/ xTlIgnGjfUVgFMyj7c9u88qlmw9qeNJH+MSjjwKQDqh2Q1KY+SPxBpuHSroAwUo3r1ws IQFm7R0iEd9fNe7HsUHpQMfFjvkJ8fZlEKtQDLiZVt6PgXBkJYMMwXeoj5x59TmEZUHS 7MKw== X-Gm-Message-State: AOAM530yuiAoh4+RPI35DfTWCwCzULW7z0dVX6C2KErClXc60nq6MCwx PWADUL6pKDh0R+Qyz2grNSumAp6usxSnOwECZ94= X-Google-Smtp-Source: ABdhPJwxGazUXRqgAN1GpZddzUaMwT6FOH9DpbnCwfX5eiMQTGKO1NoGy56MUTgvVlq3ibNlGT74HjpfS09uzjrv/xA= X-Received: by 2002:a17:907:8a14:b0:6e8:9691:62f7 with SMTP id sc20-20020a1709078a1400b006e8969162f7mr17339159ejc.497.1650438826928; Wed, 20 Apr 2022 00:13:46 -0700 (PDT) MIME-Version: 1.0 References: <20220418140342.25820-1-iain@sandoe.co.uk> <517ab527-ca77-7958-079e-673804485a42@redhat.com> In-Reply-To: <517ab527-ca77-7958-079e-673804485a42@redhat.com> From: Richard Biener Date: Wed, 20 Apr 2022 09:13:36 +0200 Message-ID: Subject: Re: [PATCH] c++, coroutines: Account for overloaded promise return_value() [PR105301]. To: Jason Merrill Cc: Iain Sandoe , GCC Patches Content-Type: text/plain; charset="UTF-8" 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-List-Received-Date: Wed, 20 Apr 2022 07:13:50 -0000 On Wed, Apr 20, 2022 at 4:19 AM Jason Merrill via Gcc-patches wrote: > > On 4/18/22 10:03, Iain Sandoe wrote: > > 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"; > > + } > > You could also use get_first_fn, but the patch is OK as is. I'm > inclined to leave backports in coroutines.cc to your discretion, you > probably have a better idea of how important they are. Likewise. Please wait until after the 11.3 release. Richard. > > + 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; > > +} >