public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95050] New: coroutine: no "mandatory copy elision" for prvalue await_resume expression.
@ 2020-05-11 9:43 okannen at gmail dot com
2020-05-14 12:48 ` [Bug c++/95050] " iains at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: okannen at gmail dot com @ 2020-05-11 9:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95050
Bug ID: 95050
Summary: coroutine: no "mandatory copy elision" for prvalue
await_resume expression.
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: okannen at gmail dot com
Target Milestone: ---
Checked with gcc version 10.1.1 20200508 (GCC) (see bellow for the `gcc -v`
output)
The result of the await-resume expression is not directly used to initialize
the result of the co_await expression.
This has the observable side effect to cause a (move) copy construction when
the result the await-resume expression is a prvalue.
I think the pertinent standard paragraph is, [expr.await]/§5.3
> [...] the await-resume expression is evaluated, and its result is the result of the await-expression.
The code bellow compiles on clang but fail to compile on gcc:
#ifdef __clang__
#include <experimental/coroutine>
using namespace std::experimental;
#else
#include <coroutine>
using namespace std;
#endif
struct task
{
struct promise_type
{
auto get_return_object () -> task
{
return {};
}
auto initial_suspend () -> suspend_never
{
return {};
}
auto final_suspend () -> suspend_always
{
return {};
}
void unhandled_exception ()
{ }
void return_void ()
{}
};
};
struct ret_type
{
ret_type () = default;
ret_type (const ret_type&) =delete;
};
struct awaiter
{
auto await_ready() const -> bool
{
return true;
}
void await_suspend (coroutine_handle<>)
{}
auto await_resume() -> ret_type
{
return {};
}
};
task f()
{
ret_type r2 {co_await awaiter{}};
};
int main()
{
auto x = f();
return 0;
}
This code was tentatively compiled with `c++ -std=c++20 -fcoroutines`
`gcc -v`:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/olivier/usr/libexec/gcc/x86_64-pc-linux-gnu/10/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --enable-libsanitizer
--prefix=/home/olivier/usr/ --with-gcc-major-version-only --disable-bootstrap
--enable-language=c,c++,lto
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.1 20200508 (GCC)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/95050] coroutine: no "mandatory copy elision" for prvalue await_resume expression.
2020-05-11 9:43 [Bug c++/95050] New: coroutine: no "mandatory copy elision" for prvalue await_resume expression okannen at gmail dot com
@ 2020-05-14 12:48 ` iains at gcc dot gnu.org
2020-06-02 18:10 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: iains at gcc dot gnu.org @ 2020-05-14 12:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95050
Iain Sandoe <iains at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |iains at gcc dot gnu.org
Target Milestone|--- |10.2
Last reconfirmed| |2020-05-14
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/95050] coroutine: no "mandatory copy elision" for prvalue await_resume expression.
2020-05-11 9:43 [Bug c++/95050] New: coroutine: no "mandatory copy elision" for prvalue await_resume expression okannen at gmail dot com
2020-05-14 12:48 ` [Bug c++/95050] " iains at gcc dot gnu.org
@ 2020-06-02 18:10 ` cvs-commit at gcc dot gnu.org
2020-06-07 21:01 ` cvs-commit at gcc dot gnu.org
2020-06-08 8:45 ` iains at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-02 18:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95050
--- 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:324276ff9b1aa5128e5cb9f5d43182d1ebab0752
commit r11-835-g324276ff9b1aa5128e5cb9f5d43182d1ebab0752
Author: Iain Sandoe <iain@sandoe.co.uk>
Date: Tue Jun 2 16:47:54 2020 +0100
coroutines: Wrap co_await in a target expr where needed [PR95050]
Since the co_await expression is mostly opaque to the existing
machinery, we were hiding the details of the await_resume return
value. If that needs to be wrapped in a target expression, then
emulate this with the whole co_await. Similarly, if the await
expression we build in response to co_await p.yield_value (e)
is wrapped in a target expression, then we need to transfer that
wrapper to the resultant CO_YIELD_EXPR (which is, itself, just
a proxy for the underlying co_await).
gcc/cp/ChangeLog:
PR c++/95050
* coroutines.cc (build_co_await): Wrap the co_await expression
in a TARGET_EXPR, where needed.
(finish_co_yield_expr): Likewise.
gcc/testsuite/ChangeLog:
PR c++/95050
* g++.dg/coroutines/pr95050.C: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/95050] coroutine: no "mandatory copy elision" for prvalue await_resume expression.
2020-05-11 9:43 [Bug c++/95050] New: coroutine: no "mandatory copy elision" for prvalue await_resume expression okannen at gmail dot com
2020-05-14 12:48 ` [Bug c++/95050] " iains at gcc dot gnu.org
2020-06-02 18:10 ` cvs-commit at gcc dot gnu.org
@ 2020-06-07 21:01 ` cvs-commit at gcc dot gnu.org
2020-06-08 8:45 ` iains at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-07 21:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95050
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Iain D Sandoe
<iains@gcc.gnu.org>:
https://gcc.gnu.org/g:ac9b05305d376cfa391dd57a46515cbdc165f094
commit r10-8261-gac9b05305d376cfa391dd57a46515cbdc165f094
Author: Iain Sandoe <iain@sandoe.co.uk>
Date: Sun Jun 7 13:47:54 2020 +0100
coroutines: Wrap co_await in a target expr where needed [PR95050]
Since the co_await expression is mostly opaque to the existing
machinery, we were hiding the details of the await_resume return
value. If that needs to be wrapped in a target expression, then
emulate this with the whole co_await. Similarly, if the await
expression we build in response to co_await p.yield_value (e)
is wrapped in a target expression, then we need to transfer that
wrapper to the resultant CO_YIELD_EXPR (which is, itself, just
a proxy for the underlying co_await).
gcc/cp/ChangeLog:
PR c++/95050
* coroutines.cc (build_co_await): Wrap the co_await expression
in a TARGET_EXPR, where needed.
(finish_co_yield_expr): Likewise.
gcc/testsuite/ChangeLog:
PR c++/95050
* g++.dg/coroutines/pr95050.C: New test.
(cherry picked from commit 324276ff9b1aa5128e5cb9f5d43182d1ebab0752)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/95050] coroutine: no "mandatory copy elision" for prvalue await_resume expression.
2020-05-11 9:43 [Bug c++/95050] New: coroutine: no "mandatory copy elision" for prvalue await_resume expression okannen at gmail dot com
` (2 preceding siblings ...)
2020-06-07 21:01 ` cvs-commit at gcc dot gnu.org
@ 2020-06-08 8:45 ` iains at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: iains at gcc dot gnu.org @ 2020-06-08 8:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95050
Iain Sandoe <iains at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #3 from Iain Sandoe <iains at gcc dot gnu.org> ---
fixed on master and for 10.2
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-06-08 8:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 9:43 [Bug c++/95050] New: coroutine: no "mandatory copy elision" for prvalue await_resume expression okannen at gmail dot com
2020-05-14 12:48 ` [Bug c++/95050] " iains at gcc dot gnu.org
2020-06-02 18:10 ` cvs-commit at gcc dot gnu.org
2020-06-07 21:01 ` cvs-commit at gcc dot gnu.org
2020-06-08 8:45 ` iains 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).