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

            Bug ID: 95736
           Summary: coroutine method improperly copies awaitable
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mizvekov at gmail dot com
  Target Milestone: ---

Created attachment 48752
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48752&action=edit
example reproduction

Compiling attached program with `g++ -std=c++20 -fcoroutines -O0 -ggdb3
test.cc` and then running gives unexpected result:

```
coro begin
suspending to footable 0x7fffee14dee0
operator() on 0x7ffff5c307e0
a.out: test.cc:33: void footable::operator()(): Assertion `handle' failed.
fish: “./a.out” terminated by signal SIGABRT (Abort)
```

Expected result, as obtained from clang with `clang++ -std=c++20 -stdlib=libc++
-O0 -ggdb3 test.cc`:
```
coro begin
suspending to footable 0x7ffff6441330
operator() on 0x7ffff6441330
resuming from footable 0x7ffff6441330
coro end
coro returns
final suspend
releasing
done
```

Notice how on the gcc (first) case, it fails because `await_suspend` and
`operator()` are operating on different copies of the awaiter, even though the
awaiter is not copy constructible.

I failed to reproduce this problem if the coroutine body was not a class
method.

Compiler explorer workspace for convenience: https://godbolt.org/z/_yqwCV

Reply via email to