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)

Reply via email to