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++/95346] New: [coroutines] coroutine return-type should be initialised with rvalue if different from get_return_object() return-type
Date: Tue, 26 May 2020 20:31:07 +0000	[thread overview]
Message-ID: <bug-95346-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 95346
           Summary: [coroutines] coroutine return-type should be
                    initialised with rvalue if different from
                    get_return_object() return-type
           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: ---

If I have the following code:

----------
#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 wrapper {
    using promise_type = task::promise_type;
    wrapper(task&&);
};

wrapper f() {
    co_return;
}
----------


Then building with GCC 10.0 and GCC trunk with -std=c++20 -fcoroutines fails
with the following compile-error:


x86-64 gcc (trunk)
-O3 -std=c++2a -Wall -fcoroutines
1
<Compilation failed>
x86-64 gcc (trunk) - 368ms
<source>: In function 'wrapper f()':

error: cannot bind rvalue reference of type 'task&&' to lvalue of type 'task'
   30 | }
      | ^
note:   initializing argument 1 of 'wrapper::wrapper(task&&)'
   25 |     wrapper(task&&);


I think the return-value of a coroutine should be initialised with an
rvalue-reference to the object returned from get_return_object() if the
two objects have different types. GCC seems to be trying to initialise
the return-value using an lvalue-reference to the object returned from
get_return_object().

Both Clang and MSVC accept this code, while GCC does not.
See https://godbolt.org/z/4RRtaL

             reply	other threads:[~2020-05-26 20:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 20:31 lewissbaker.opensource at gmail dot com [this message]
2020-05-27 19:42 ` [Bug c++/95346] " iains at gcc dot gnu.org
2020-06-04 18:26 ` cvs-commit at gcc dot gnu.org
2020-06-10 20:59 ` cvs-commit at gcc dot gnu.org
2020-06-12 17:55 ` 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-95346-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).