public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lewissbaker.opensource at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/95350] New: [coroutines] coroutines with move-only by-value parameters attempt to copy parameter instead of move it
Date: Tue, 26 May 2020 21:19:40 +0000 [thread overview]
Message-ID: <bug-95350-4@http.gcc.gnu.org/bugzilla/> (raw)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95350
Bug ID: 95350
Summary: [coroutines] coroutines with move-only by-value
parameters attempt to copy parameter instead of move
it
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: lewissbaker.opensource at gmail dot com
Target Milestone: ---
The following code fails to compile under GCC 10.0 and GCC trunk.
Compile with -fcoroutines -std=c++2a
See https://godbolt.org/z/zB_RVC
This code compiles successfully under both Clang and MSVC coroutines
implementations.
-------------
#include <coroutine>
struct task {
struct promise_type {
task get_return_object();
void return_void();
void unhandled_exception();
std::suspend_always initial_suspend() noexcept;
std::suspend_always final_suspend() noexcept;
};
};
struct move_only {
move_only();
move_only(const move_only&) = delete;
move_only(move_only&) = delete;
move_only(move_only&&) = default;
};
task f(move_only x) {
co_return;
}
---------------------
Fails with compile-error:
<source>: In function 'task f(move_only)':
<source>:30:1: error: use of deleted function 'move_only::move_only(const
move_only&)'
30 | }
| ^
<source>:24:5: note: declared here
24 | move_only(move_only&) = delete;
| ^~~~~~~~~
When copying parameters into the coroutine frame which are passed by value
it should be initialising the parameter copy using an xvalue referring to the
original function parameter. Whereas it seems like GCC is attempting to
initialise the parameter-copy with an lvalue-reference to the original
parameter, which ends up calling the copy-constructor.
See http://eel.is/c++draft/dcl.fct.def.coroutine#13
> ... the copy is a variable of type cv T with automatic storage duration
> that is direct-initialized from an xvalue of type T referring to the
> parameter ...
next reply other threads:[~2020-05-26 21:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-26 21:19 lewissbaker.opensource at gmail dot com [this message]
2020-05-27 19:41 ` [Bug c++/95350] " iains at gcc dot gnu.org
2020-06-01 19:25 ` cvs-commit at gcc dot gnu.org
2020-06-12 17:32 ` cvs-commit at gcc dot gnu.org
2020-06-12 17:54 ` iains 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-95350-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).