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

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