Skip to content

[coroutines/c++] Return object is being prematurely converted. #56532

Closed
@no-more-secrets

Description

@no-more-secrets

using llvm/clang main built on 2022-07-14.

There appears to be a regression in how coroutine return objects are implicitly converted prior to returning them.

First as background, the get_return_object customization point is allowed to return an object that can be implicitly converted to the real return type. This part is still working fine.

The regression concerns when this implicit conversion happens.

Clang traditionally waited to perform this implicit conversion until after the return_value customization point was called. This allowed doing some tricks that are useful in implementing e.g. a std::optional coroutine. So if you were to print out the order of calls, it would looks like this traditionally:

  1. call get_return_object
  2. call return_value
  3. do implicit conversion of return object to the type that is actually needed.

This may have changed at some point in the last few months, but the version of clang that I built today does it in a different order:

  1. call get_return object
  2. do implicit conversion of return object to the type that is actually needed.
  3. call return_value

I'm not sure if the standard guarantees that it will happen in a certain order... but I know that traditionally it used to be done according to the first ordering (which gcc also does), but now that changed, and it is breaking my implementation of the std::optional coroutine.

It seems sensible to wait as long as possible to perform the implicit conversion, since it affords flexibility to the user in that it permits the object that get_return_object returns to remain alive and accessible to return_value (or other customization point methods) until the very end when it is implicitly converted just before ending the coroutine.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions