public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lemourin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-99575-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99575

            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(<coroutine>)
#include <coroutine>
namespace stdx {
using std::coroutine_handle;
using std::noop_coroutine;
using std::suspend_always;
using std::suspend_never;
}  // namespace stdx
#elif __has_include(<experimental/coroutine>)
#include <experimental/coroutine>
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<void> continuation) {}
  void await_resume() {}
};

class NonMoveableTask {
 public:
  NonMoveableTask() = default;
  NonMoveableTask(const NonMoveableTask&) = delete;
  NonMoveableTask(NonMoveableTask&&) = delete;

  NonMoveableTask& operator=(const NonMoveableTask&) = delete;
  NonMoveableTask& operator=(NonMoveableTask&& other) = delete;

  bool await_ready() const { return false; }
  void await_suspend(stdx::coroutine_handle<void>) {}
  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 log:
`
move.cc: In function ‘Task Foo(NonMoveableTask*)’:
move.cc:50:45: error: use of deleted function
‘NonMoveableTask::NonMoveableTask(NonMoveableTask&&)’
   50 | Task Foo(NonMoveableTask* task) { co_await* task; }
      |                                             ^~~~
move.cc:40:3: note: declared here
   40 |   NonMoveableTask(NonMoveableTask&&) = delete;
      |   ^~~~~~~~~~~~~~~
make: *** [<builtin>: 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.

             reply	other threads:[~2021-03-13 13:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-13 13:37 lemourin at gmail dot com [this message]
2021-09-30 19:56 ` [Bug c++/99575] " iains at gcc dot gnu.org
2021-09-30 19:56 ` iains at gcc dot gnu.org
2021-10-02 18:38 ` iains at gcc dot gnu.org
2021-10-03 19:42 ` cvs-commit at gcc dot gnu.org
2022-06-28 10:43 ` jakub at gcc dot gnu.org
2023-03-24 12:27 ` niget.tom at gmail dot com
2023-07-07  9:31 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99575-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).