Title
Initialization of coroutine result object
Status
open
Section
9.5.4 [dcl.fct.def.coroutine]
Submitter
Tomasz KamiƄski

Created on 2022-04-06.00:00:00 last changed 1 month ago

Messages

Date: 2022-04-06.15:19:39

Suggested resolution:

Change in 9.5.4 [dcl.fct.def.coroutine] paragraph 7 as follows:

The expression promise.get_return_object() is used to initialize the The returned reference or prvalue result object of a call to a coroutine is copy-initialized with promise.get_return_object(). The call to get_return_object initialization is sequenced before the call to initial-suspend and is invoked at most once.
Date: 2022-04-06.00:00:00

Subclause 9.5.4 [dcl.fct.def.coroutine] paragraph 7 specifies:

The expression promise.get_return_object() is used to initialize the returned reference or prvalue 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.

It is unclear:

  • whether get_return_object() is invoked inside or outside of the try-block shown in paragraph 5 (see issue 2562),
  • whether the prvalue result object may be initialized later (e.g. before the first actual suspension), and
  • if the initialization does occur later, by what mechanism the prvalue result of get_return_object is forwarded to that initialization.

There is implementation divergence.

Note that a user-defined conversion may be involved in the initialization of the coroutine's prvalue result object from get_return_object(). Note also that the return type of get_return_object might be non-copyable and non-movable. However, there are certain programming patterns that would benefit from a late-initialized return value.

See also compiler explorer.

History
Date User Action Args
2022-04-06 15:19:39adminsetmessages: + msg6790
2022-04-06 00:00:00admincreate