From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E9640395B42B; Tue, 26 May 2020 21:19:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9640395B42B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1590527980; bh=8pJP1NxJ1Vob9sg5WW+EHiRfpVDrqpwrGrdA6RlEnnk=; h=From:To:Subject:Date:From; b=qQpYJ+BUZmK1KOEXiy2HizivU9jVtkxu6Wg005ALwcZqA7AjsgeozwIlB/1/gf9Tj e4VEg0GyO4BiuE7Vu7iB6btPiGwG0xy6Lpyd9l/c+8Pnos5BLxB4Ur9dAX6bUr/skU /OpiLiUILxxZeBJJJgNE4dqvyG/toUTwqiIJ8FVM= From: "lewissbaker.opensource at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95350] New: [coroutines] coroutines with move-only by-value parameters attempt to copy parameter instead of move it Date: Tue, 26 May 2020 21:19:40 +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 21:19:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95350 Bug ID: 95350 Summary: [coroutines] coroutines with move-only by-value parameters attempt to copy parameter instead of move it 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: --- The following code fails to compile under GCC 10.0 and GCC trunk. Compile with -fcoroutines -std=3Dc++2a See https://godbolt.org/z/zB_RVC This code compiles successfully under both Clang and MSVC coroutines implementations. ------------- #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 move_only { move_only(); move_only(const move_only&) =3D delete; move_only(move_only&) =3D delete; move_only(move_only&&) =3D default; }; task f(move_only x) { co_return; } --------------------- Fails with compile-error: : In function 'task f(move_only)': :30:1: error: use of deleted function 'move_only::move_only(const move_only&)' 30 | } | ^ :24:5: note: declared here 24 | move_only(move_only&) =3D delete; | ^~~~~~~~~ When copying parameters into the coroutine frame which are passed by value it should be initialising the parameter copy using an xvalue referring to t= he original function parameter. Whereas it seems like GCC is attempting to initialise the parameter-copy with an lvalue-reference to the original parameter, which ends up calling the copy-constructor. See http://eel.is/c++draft/dcl.fct.def.coroutine#13 > ... the copy is a variable of type cv T with automatic storage duration > that is direct-initialized from an xvalue of type T referring to the > parameter ...=