C++ Logo


Advanced search

Re: [std-proposals] Allowing coroutine_handle::from_promise to accept a pointer-interconvertible object

From: Aaron Jacobs <jacobsa_at_[hidden]>
Date: Wed, 4 Jan 2023 18:11:30 +1100
On Wed, Jan 4, 2023 at 3:27 PM Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]> wrote:
> But in fact the "promise object of the coroutine" literally is that
> very `Promise<Result>` object, which is-a `PromiseBase` object. Every
> `Promise<Result>` object is by definition a `PromiseBase` object,
> and every pointer to a `Promise<Result>` object is a pointer to a
> `PromiseBase` object, and this particular `Promise<Result>` object
> (pointed to by the `PromiseBase`-pointer you have) literally is
> the promise object of a coroutine. I can't see any rationale by
> which someone could point to an object in an execution of this
> particular C++ program and say, "Look, this object is-a PromiseBase,
> but simultaneously this same object is not the promise object of any
> coroutine." There's only one object here!

I understand and agree with this in a practical sense; to be clear I am
talking only about language lawyering here.

But whichever way you come down on the language lawyer question, I think you
have to agree there is some problem with the wording here. Imagine for the
moment that we take your point of view and say it's already okay to bind the
reference to an object that's a superclass of the handle's promise type. Then
it's impossible to implement the function correctly with the existing ABIs,
because the address you get from the subclass reference may not be the same
as the actual promise's address. If this is intended to be allowed, it needs
to be restricted so that the objects are pointer-interconvertible and have
the same alignment.

Received on 2023-01-04 07:11:57