From patchwork Sat Oct 3 05:25:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 145185 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1EFB4BA9036 for ; Sat, 3 Oct 2026 05:27:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1EFB4BA9036 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bYgEQc37 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 ESMTP id 949F44BA9033 for ; Sat, 3 Oct 2026 05:26:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 949F44BA9033 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 949F44BA9033 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791005178; cv=none; b=Eg508vHH2WIpsFWx9IfWbCXkfQcrxt5j2mEwL4lMAO973tf4bDiJWDlEP7bQaperfCygkZ8xxeC8tO8SUEl2A1DJFMiB+U/ZhOmnQCF9ssMh+KSKLrd275Bscx4i+6Ndc0KHymZcKtuafK3tvdKoQm9zvDXNVDhQiqPciqiJabM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791005178; c=relaxed/simple; bh=Miel6WAUl3/zbyGX2xQ4xoll4hoMK5i7ELGPC1UC5Zk=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=PrIlW5nNM/uoYSC8sehuIwQCCb7R0Wx7Xiv1m7jEq4V7Qv2jP38e2zP/oxzKrxY3M2gTtqQbC8JWU/XBJ9p0uH2h0sJoccZjrpcJQxpGwnICagq/wzqt91wvvXo4ZYHNrHJ2UWO2FHjW0xTea57v2ddOHKqgJu2XWNVfqSBwFyI= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bYgEQc37 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 949F44BA9033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791005178; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U/X/BX1+yHCQQVWkSWDtIHwfwtyW08OP6uEJQ+tKx7w=; b=bYgEQc37NSJbtAN+cEPZ9FFG5lCfrCB0qxs9TT6hruvcwECWeIBxqD2dVmkRW9S+kTIJTJ 3KVVL8NZMtB1qXgkSo77+2PAw6rPg3RRtd6Ibd1W4A+CeQOriNhdZXCUbgtUfJexxoJeHy i3NDGhil+qMRzZRZtf8V5kJN+GO2/jc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-rct78qaPMdGmcLWlsTcr9A-1; Sat, 03 Oct 2026 01:26:14 -0400 X-MC-Unique: rct78qaPMdGmcLWlsTcr9A-1 X-Mimecast-MFC-AGG-ID: rct78qaPMdGmcLWlsTcr9A_1791005174 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A26A91944B1B; Sat, 3 Oct 2026 05:26:13 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.44.33.31]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AF14B30000E3; Sat, 3 Oct 2026 05:26:12 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 6935Q5C44053697 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 3 Oct 2026 07:26:05 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 6935PtVv4053696; Sat, 3 Oct 2026 07:25:55 +0200 Date: Sat, 3 Oct 2026 07:25:50 +0200 From: Jakub Jelinek To: Jason Merrill Cc: Iain Sandoe , gcc-patches@gcc.gnu.org Subject: [PATCH] c++, v2: Implement C++29 P3950R1 - return_value & return_void Are Not Mutually Exclusive paper as DR [PR125830] Message-ID: References: <89389c54-766b-4484-8cc8-12b01c3fc880@redhat.com> MIME-Version: 1.0 In-Reply-To: <89389c54-766b-4484-8cc8-12b01c3fc880@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: OtE9TDMewv22UsNLnO0V2uDx_7JvGD-iJJSNTOwzZlQ_1791005174 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org On Fri, Oct 02, 2026 at 11:20:45PM +0200, Jason Merrill wrote: > Everything in that function should change tf_warning_or_error to complain. Ok, here is an updated patch which adds it to the remaining call - build_op_call. > > So far lightly tested (on coroutines/* and affected tests), ok for trunk > > if it passes full bootstrap/regtest? And what to do about the above > > mentioned bugs in the code being removed? Shall I address those first > > and then send this patch to remove it afterwards (and just backport that > > first patch and not the second)? > > Do you think it's important to fix those bugs on release branches? They > sound like minor diagnostic quality issues. It is an ICE after error, e.g. g++ 15.2.1 emits on: #if __has_include() #include #else #include namespace std { using namespace experimental; } #endif struct dummy_coroutine {}; namespace std { template<> class coroutine_traits<::dummy_coroutine> { public: struct promise_type { void return_value(int x) { } void return_void() {} void return_void(int) {} std::suspend_never initial_suspend() noexcept { return {}; } std::suspend_never final_suspend() noexcept { return {}; } dummy_coroutine get_return_object() { return {}; } void unhandled_exception() {} }; }; } int x; dummy_coroutine foo() { if (x == 1) co_return 17; else if (x == 2) co_return; else if (x == 3) co_return; } g++ -S -std=c++20 /tmp/pr97438.C -o /tmp/pr97438.s /tmp/pr97438.C: In function ‘dummy_coroutine foo()’: /tmp/pr97438.C:31:1: error: the coroutine promise type ‘std::__n4861::coroutine_traits::promise_type’ declares both ‘return_value’ and ‘return_void’ 31 | foo() { | ^~~ /tmp/pr97438.C:-61845579:33: note: ‘return_void’ declared here /tmp/pr97438.C:16:14: note: ‘return_value’ declared here 16 | void return_value(int x) { } | ^~~~~~~~~~~~ /tmp/pr97438.C:35: confused by earlier errors, bailing out Preprocessed source stored into /tmp/cc2bwCtQ.out file, please attach this to your bugreport. Anyway, following patch has been successfully bootstrapped/regtested on x86_64-linux and i686-linux. 2026-10-03 Jakub Jelinek P3950R1 PR c++/125830 * c-cppbuiltin.cc (c_cpp_builtins): Bump __cpp_impl_coroutine from 201902L to 202606L. * coroutines.cc: Implement C++29 P3950R1 - return_value & return_void Are Not Mutually Exclusive paper as DR. (struct coroutine_info): Remove coro_co_return_error_emitted member. (coro_promise_type_found_p): Remove diagnostics about both return_void and return_value successful lookup. (lookup_promise_method): Add complain argument, pass it down to lookup_member. (coro_build_promise_expression): Add complain argument, pass it down to lookup_promise_method, build_new_method_call and build_class_member_access_expr. (get_coroutine_return_void_expr): Pass tf_none to coro_build_promise_expression. * g++.dg/DRs/dr2581-2.C (__cpp_impl_coroutine): Redefine to 202606L rather than 201902L. * g++.dg/coroutines/pr105301.C: Change dg-error to dg-bogus. * g++.dg/coroutines/coro-pre-proc.C: Expect different value of __cpp_impl_coroutine. * g++.dg/coroutines/pr97438.C: Change dg-error to dg-bogus. * g++.dg/coroutines/p3950r1.C: New test. Jakub --- a/gcc/c-family/c-cppbuiltin.cc 2026-09-10 16:56:41.686638893 +0200 +++ b/gcc/c-family/c-cppbuiltin.cc 2026-10-01 12:42:04.068512619 +0200 @@ -1152,7 +1152,7 @@ c_cpp_builtins (cpp_reader *pfile) else if (cxx_dialect >= cxx20) cpp_warn (pfile, "__cpp_modules"); if (flag_coroutines) - cpp_define (pfile, "__cpp_impl_coroutine=201902L"); /* n4861, DIS */ + cpp_define (pfile, "__cpp_impl_coroutine=202606L"); /* n4861, DIS */ else if (cxx_dialect >= cxx20) cpp_warn (pfile, "__cpp_impl_coroutine"); if (flag_tm) --- a/gcc/cp/coroutines.cc 2026-09-25 17:52:15.184532722 +0200 +++ g/gcc/cp/coroutines.cc 2026-10-02 23:36:36.084757544 +0200 @@ -298,7 +298,6 @@ struct GTY((for_user)) coroutine_info /* Flags to avoid repeated errors for per-function issues. */ bool coro_ret_type_error_emitted; bool coro_promise_error_emitted; - bool coro_co_return_error_emitted; }; struct coroutine_info_hasher : ggc_ptr_hash @@ -825,37 +824,6 @@ coro_promise_type_found_p (tree fndecl, return false; } - /* Test for errors in the promise type that can be determined now. */ - tree has_ret_void = lookup_member (coro_info->promise_type, - coro_return_void_identifier, - /*protect=*/1, /*want_type=*/0, - tf_none); - tree has_ret_val = lookup_member (coro_info->promise_type, - coro_return_value_identifier, - /*protect=*/1, /*want_type=*/0, - tf_none); - if (has_ret_void && has_ret_val) - { - auto_diagnostic_group d; - location_t ploc = DECL_SOURCE_LOCATION (fndecl); - if (!coro_info->coro_co_return_error_emitted) - error_at (ploc, "the coroutine promise type %qT declares both" - " % and %", - coro_info->promise_type); - inform (DECL_SOURCE_LOCATION (BASELINK_FUNCTIONS (has_ret_void)), - "% 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; - } - /* Try to find the handle type for the promise. */ tree handle_type = instantiate_coro_handle_for_promise_type (loc, coro_info->promise_type); @@ -1028,12 +996,13 @@ get_coroutine_from_address (tree decl) static tree lookup_promise_method (tree fndecl, tree member_id, location_t loc, - bool musthave) + bool musthave, + tsubst_flags_t complain = tf_warning_or_error) { tree promise = get_coroutine_promise_type (fndecl); tree pm_memb = lookup_member (promise, member_id, - /*protect=*/1, /*want_type=*/0, tf_warning_or_error); + /*protect=*/1, /*want_type=*/0, complain); if (musthave && pm_memb == NULL_TREE) { error_at (loc, "no member named %qE in %qT", member_id, promise); @@ -1051,9 +1020,10 @@ lookup_promise_method (tree fndecl, tree static tree coro_build_promise_expression (tree fn, tree promise_obj, tree member_id, location_t loc, vec **args, - bool musthave) + bool musthave, + tsubst_flags_t complain = tf_warning_or_error) { - tree meth = lookup_promise_method (fn, member_id, loc, musthave); + tree meth = lookup_promise_method (fn, member_id, loc, musthave, complain); if (meth == error_mark_node) return error_mark_node; @@ -1067,17 +1037,17 @@ coro_build_promise_expression (tree fn, tree expr; if (BASELINK_P (meth)) expr = build_new_method_call (promise, meth, args, NULL_TREE, - LOOKUP_NORMAL, NULL, tf_warning_or_error); + LOOKUP_NORMAL, NULL, complain); else { expr = build_class_member_access_expr (promise, meth, NULL_TREE, - true, tf_warning_or_error); + true, complain); vec *real_args; if (!args) real_args = make_tree_vector (); else real_args = *args; - expr = build_op_call (expr, &real_args, tf_warning_or_error); + expr = build_op_call (expr, &real_args, complain); } return expr; } @@ -1094,7 +1064,7 @@ get_coroutine_return_void_expr (tree dec info->return_void = coro_build_promise_expression (current_function_decl, NULL, coro_return_void_identifier, - loc, NULL, musthave); + loc, NULL, musthave, tf_none); /* Don't return an error if it's an optional call. */ if (!musthave && info->return_void == error_mark_node) return NULL_TREE; --- a/gcc/testsuite/g++.dg/DRs/dr2581-2.C 2026-08-06 11:48:09.058480111 +0200 +++ b/gcc/testsuite/g++.dg/DRs/dr2581-2.C 2026-10-01 12:44:13.876768629 +0200 @@ -61,7 +61,7 @@ #define __cpp_hex_float 201603L // { dg-error "'__cpp_hex_float' redefined" "" { target c++20 } } #define __cpp_if_consteval 202106L // { dg-error "'__cpp_if_consteval' redefined" "" { target c++23 } } #define __cpp_if_constexpr 201606L // { dg-error "'__cpp_if_constexpr' redefined" "" { target c++20 } } -#define __cpp_impl_coroutine 201902L // { dg-error "'__cpp_impl_coroutine' redefined" "" { target c++20 } } +#define __cpp_impl_coroutine 202606L // { dg-error "'__cpp_impl_coroutine' redefined" "" { target c++20 } } #define __cpp_impl_destroying_delete 201806L // { dg-error "'__cpp_impl_destroying_delete' redefined" "" { target c++20 } } #define __cpp_impl_three_way_comparison 201907L // { dg-error "'__cpp_impl_three_way_comparison' redefined" "" { target c++20 } } #define __cpp_impl_reflection 202603L // { dg-error "'__cpp_impl_reflection' redefined" "" { target c++26 } } --- a/gcc/testsuite/g++.dg/coroutines/pr105301.C 2026-03-27 10:17:15.380310407 +0100 +++ b/gcc/testsuite/g++.dg/coroutines/pr105301.C 2026-10-01 12:40:29.792779226 +0200 @@ -46,7 +46,7 @@ struct bad_promise_6 { }; coro -bad_implicit_return() // { dg-error {.aka 'bad_promise_6'. declares both 'return_value' and 'return_void'} } +bad_implicit_return() // { dg-bogus {.aka 'bad_promise_6'. declares both 'return_value' and 'return_void'} } { co_await a; } --- a/gcc/testsuite/g++.dg/coroutines/coro-pre-proc.C 2026-03-27 10:17:15.379310423 +0100 +++ b/gcc/testsuite/g++.dg/coroutines/coro-pre-proc.C 2026-10-01 12:44:29.900553347 +0200 @@ -4,6 +4,6 @@ #error "coroutines should engaged." #endif -#if __cpp_impl_coroutine != 201902L +#if __cpp_impl_coroutine != 202606L #error "coroutine version out of sync." #endif --- a/gcc/testsuite/g++.dg/coroutines/pr97438.C 2026-03-27 10:17:15.384310342 +0100 +++ b/gcc/testsuite/g++.dg/coroutines/pr97438.C 2026-10-01 12:46:40.857793918 +0200 @@ -25,6 +25,6 @@ public: } dummy_coroutine -foo() { // { dg-error {the coroutine promise type 'std::__n4861::coroutine_traits::promise_type' declares both 'return_value' and 'return_void'} } +foo() { // { dg-bogus {the coroutine promise type 'std::__n4861::coroutine_traits::promise_type' declares both 'return_value' and 'return_void'} } co_return 17; } --- a/gcc/testsuite/g++.dg/coroutines/p3950r1.C 2026-10-01 12:52:43.323958890 +0200 +++ b/gcc/testsuite/g++.dg/coroutines/p3950r1.C 2026-10-01 13:06:52.331832286 +0200 @@ -0,0 +1,74 @@ +// C++29 P3950R1 - return_value & return_void Are Not Mutually Exclusive + +#include +#include + +struct dummy_coroutine1 {}; +template +struct dummy_coroutine2 {}; + +namespace std { + +template<> +class coroutine_traits<::dummy_coroutine1> { +public: + struct promise_type { + void return_value(int x) {} + void return_value(double x) {} + void return_void() {} + std::suspend_never initial_suspend() noexcept { return {}; } + std::suspend_never final_suspend() noexcept { return {}; } + dummy_coroutine1 get_return_object() { return {}; } + void unhandled_exception() {} + }; +}; + +template +class coroutine_traits<::dummy_coroutine2> { +public: + struct promise_type { + template + void return_value(U x) requires std::is_same_v {} + void return_void() requires std::is_same_v {} + std::suspend_never initial_suspend() noexcept { return {}; } + std::suspend_never final_suspend() noexcept { return {}; } + dummy_coroutine2 get_return_object() { return {}; } + void unhandled_exception() {} + }; +}; + +} + +int x; + +dummy_coroutine1 +foo () +{ + if (x == 1) + co_return 17; + else if (x == 2) + co_return 17.0; + else if (x == 3) + co_return; +} + +dummy_coroutine2 +bar () +{ + if (x == 4) + co_return; +} + +dummy_coroutine2 +baz () +{ + if (x == 5) + co_return 42; +} + +dummy_coroutine2 +qux () +{ + if (x == 6) + co_return 42.0; +}