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

            Bug ID: 103963
           Summary: Coroutine return type must not be copy- or
                    move-constructible
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This is a valid program:
```
#include <coroutine>

class task {
public:
    class task_promise {
    public:
        task get_return_object() { return
task{handle_type::from_promise(*this)}; }
        auto initial_suspend() { return std::suspend_always{}; }
        auto final_suspend() noexcept { return std::suspend_never{}; }
        void return_void() {}
        void unhandled_exception() {}
    };
    using handle_type = std::coroutine_handle<task_promise>;
    handle_type handle;

    auto await_ready() { return false; }
    auto await_suspend(handle_type) { return handle; }
    void await_resume() { handle.resume(); }

    using promise_type = task_promise;
    task(handle_type h) : handle(h) {}
    task(const task&) = delete;
    task& operator=(const task&) = delete;
    task(task&&) = delete;
    task& operator=(task&&) = delete;
};

int main() {
    task f = []() -> task { co_return; }();
    task g = [&f]() -> task { co_await f; }();
    g.handle.resume();
}
```

The code is accepted in MSVC, but not in GCC.

GCC 11.2 complains on the missing move-constructor:
error: use of deleted function 'task::task(task&&)'

and GCC trunk - on the missing copy-constructor:
error: use of deleted function 'task::task(const task&)'

Demo: https://gcc.godbolt.org/z/1c7fajqn8

Related discussion: https://stackoverflow.com/q/70641924/7325599

Reply via email to