From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0A1633857C63; Sat, 13 Mar 2021 13:37:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A1633857C63 From: "lemourin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object Date: Sat, 13 Mar 2021 13:37:57 +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.2.1 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: lemourin 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 keywords 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: Sat, 13 Mar 2021 13:37:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99575 Bug ID: 99575 Summary: [coroutines] unexpected move when co_awaiting a nonmoveable object Product: gcc Version: 10.2.1 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lemourin at gmail dot com Target Milestone: --- ``` #if __has_include() #include namespace stdx { using std::coroutine_handle; using std::noop_coroutine; using std::suspend_always; using std::suspend_never; } // namespace stdx #elif __has_include() #include namespace stdx { using std::experimental::coroutine_handle; using std::experimental::noop_coroutine; using std::experimental::suspend_always; using std::experimental::suspend_never; } // namespace stdx #else #error "coroutines unsupported" #endif class Task { public: struct promise_type { Task get_return_object() { return Task{}; } stdx::suspend_always initial_suspend() { return {}; } stdx::suspend_always final_suspend() noexcept { return {}; } void unhandled_exception() {} void return_void() {} }; bool await_ready() const { return false; } void await_suspend(stdx::coroutine_handle continuation) {} void await_resume() {} }; class NonMoveableTask { public: NonMoveableTask() =3D default; NonMoveableTask(const NonMoveableTask&) =3D delete; NonMoveableTask(NonMoveableTask&&) =3D delete; NonMoveableTask& operator=3D(const NonMoveableTask&) =3D delete; NonMoveableTask& operator=3D(NonMoveableTask&& other) =3D delete; bool await_ready() const { return false; } void await_suspend(stdx::coroutine_handle) {} void await_resume() {} }; Task Foo(NonMoveableTask* task) { co_await* task; } int main() {} ``` The above code snippet does not compile with gcc with the following error l= og: ` move.cc: In function =E2=80=98Task Foo(NonMoveableTask*)=E2=80=99: move.cc:50:45: error: use of deleted function =E2=80=98NonMoveableTask::NonMoveableTask(NonMoveableTask&&)=E2=80=99 50 | Task Foo(NonMoveableTask* task) { co_await* task; } | ^~~~ move.cc:40:3: note: declared here 40 | NonMoveableTask(NonMoveableTask&&) =3D delete; | ^~~~~~~~~~~~~~~ make: *** [: move] Error 1 ` clang and msvc accept it. If the move constructor is available code compiled with gcc uses it and leaves `task` in a moved from state.=