[Bug c++/115908] New: [coroutines] Wrong behavior of using get_return_object() coroutines creation
ddvamp007 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Jul 13 12:54:16 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115908
Bug ID: 115908
Summary: [coroutines] Wrong behavior of using
get_return_object() coroutines creation
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ddvamp007 at gmail dot com
Target Milestone: ---
The standard says: "The expression promise.get_return_object() is used to
initialize the returned reference or value result object of a call to a
coroutine. The call to get_return_object is sequenced before the call to
initial_suspend and is invoked at most once." [dcl.fct.def.coroutine]
However, if you look at the result of the following program
https://godbolt.org/z/nY8Yo6vGs, it can be seen that the standard is not being
followed.
Firstly, it is not the expression itself that is used for initialization, but
its result
Secondly, if this result is a reference, it is still stored as a value
As a consequence, the behavior is not what the user expects. If we return an
non-copyable and non-movable object type referece, we will get a compilation
error. If the result contains references to the promise object, it may be
destroyed before it is used. etc.
P.S. The same thing is observed in clang
More information about the Gcc-bugs
mailing list