From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 49B913851C0C; Tue, 26 May 2020 20:31:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49B913851C0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1590525067; bh=I7HxhxWOm77NsxTU1ojIGptri3cE77tfRNvxjFdpmQo=; h=From:To:Subject:Date:From; b=d+1JxMFTYYK6OTWfZbOeyQPChGcIg7mSrCSt9UHozc+fm29pJU9DwUnAFDSn7c9g9 iFvuRtXs7FnGk2H6VJzVs77TN7fd8hwExvVLaLxGe1jMvczR7qpl1ncY1uNP22xjQL h5K/99O9cvbTypfFALUTn5kYPe6j5P5nkny6YK9M= From: "lewissbaker.opensource at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95346] New: [coroutines] coroutine return-type should be initialised with rvalue if different from get_return_object() return-type Date: Tue, 26 May 2020 20:31:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lewissbaker.opensource at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 May 2020 20:31:07 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95346 Bug ID: 95346 Summary: [coroutines] coroutine return-type should be initialised with rvalue if different from get_return_object() return-type Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lewissbaker.opensource at gmail dot com Target Milestone: --- If I have the following code: ---------- #include struct task { struct promise_type { task get_return_object(); void return_void(); void unhandled_exception(); std::suspend_always initial_suspend() noexcept; std::suspend_always final_suspend() noexcept; }; }; struct wrapper { using promise_type =3D task::promise_type; wrapper(task&&); }; wrapper f() { co_return; } ---------- Then building with GCC 10.0 and GCC trunk with -std=3Dc++20 -fcoroutines fa= ils with the following compile-error: x86-64 gcc (trunk) -O3 -std=3Dc++2a -Wall -fcoroutines 1 x86-64 gcc (trunk) - 368ms : In function 'wrapper f()': error: cannot bind rvalue reference of type 'task&&' to lvalue of type 'tas= k' 30 | } | ^ note: initializing argument 1 of 'wrapper::wrapper(task&&)' 25 | wrapper(task&&); I think the return-value of a coroutine should be initialised with an rvalue-reference to the object returned from get_return_object() if the two objects have different types. GCC seems to be trying to initialise the return-value using an lvalue-reference to the object returned from get_return_object(). Both Clang and MSVC accept this code, while GCC does not. See https://godbolt.org/z/4RRtaL=