public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object
@ 2021-03-13 13:37 lemourin at gmail dot com
  2021-09-30 19:56 ` [Bug c++/99575] " iains at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: lemourin at gmail dot com @ 2021-03-13 13:37 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/99575] [coroutines] unexpected move when co_awaiting a nonmoveable object
  2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
@ 2021-09-30 19:56 ` iains at gcc dot gnu.org
  2021-09-30 19:56 ` iains at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: iains at gcc dot gnu.org @ 2021-09-30 19:56 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-09-30
                 CC|                            |iains at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/99575] [coroutines] unexpected move when co_awaiting a nonmoveable object
  2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
  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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: iains at gcc dot gnu.org @ 2021-09-30 19:56 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/99575] [coroutines] unexpected move when co_awaiting a nonmoveable object
  2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
  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
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: iains at gcc dot gnu.org @ 2021-10-02 18:38 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/99575] [coroutines] unexpected move when co_awaiting a nonmoveable object
  2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
                   ` (2 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-03 19:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain D Sandoe <iains@gcc.gnu.org>:

https://gcc.gnu.org/g:0ee1ab15c237ffb50be1a5ce9c5e542b16df4d12

commit r12-4099-g0ee1ab15c237ffb50be1a5ce9c5e542b16df4d12
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Sat Oct 2 12:44:01 2021 +0100

    coroutines: Look through NOPs for awaiter variables [PR 99575].

    There was a missing STRIP_NOPS which meant that, in some cases,
    an awaiter variable could be hidden by a view-convert-expr.

    Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

            PR c++/99575

    gcc/cp/ChangeLog:

            * coroutines.cc (build_co_await): Strip NOPs from
            candidate awaiter expressions before testing to see
            if they need a temporary.

    gcc/testsuite/ChangeLog:

            * g++.dg/coroutines/pr99575.C: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/99575] [coroutines] unexpected move when co_awaiting a nonmoveable object
  2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
                   ` (3 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/99575] [coroutines] unexpected move when co_awaiting a nonmoveable object
  2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: niget.tom at gmail dot com @ 2023-03-24 12:27 UTC (permalink / raw)
  To: gcc-bugs

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

Tom Niget <niget.tom at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |niget.tom at gmail dot com

--- Comment #3 from Tom Niget <niget.tom at gmail dot com> ---
FWIW, the code in Paweł's comment compiles under 12.1 (and doesn't compile
under 11.3). Maybe this can be closed?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/99575] [coroutines] unexpected move when co_awaiting a nonmoveable object
  2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
                   ` (5 preceding siblings ...)
  2023-03-24 12:27 ` niget.tom at gmail dot com
@ 2023-07-07  9:31 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07  9:31 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |12.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed in GCC 12, not a regression.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-07  9:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-13 13:37 [Bug c++/99575] New: [coroutines] unexpected move when co_awaiting a nonmoveable object lemourin at gmail dot com
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

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).