C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] async coroutines vs. lambdas
From: Marcin Jaczewski (marcinjaczewski86_at_[hidden])
Date: 2020-05-14 09:06:13


czw., 14 maj 2020 o 15:55 Ville Voutilainen
<ville.voutilainen_at_[hidden]> napisał(a):
>
> On Thu, 14 May 2020 at 16:53, Ville Voutilainen
> <ville.voutilainen_at_[hidden]> wrote:
> >
> > On Thu, 14 May 2020 at 16:31, Marcin Jaczewski via Std-Proposals
> > <std-proposals_at_[hidden]> wrote:
> > > And code like:
> > >
> > > ```
> > > lazy<int> get_custom_lambda() {
> > > struct X
> > > {
> > > int i = 3;
> > > lazy<int> operator()(){ co_return i; }
> > > } x();
> > > return x();
> > > }
> > >
> > > ```
> > >
> > > This still crash, and this is same code as `get_real_lambda`.
> > > How do you like fix it? and what if lambda is not movable?
> >
> > If I swap those co_return/return, will this code then work?
>
> And follow-up question, what if they're both co_returns?

If we change last `return` to `co_returns` then object `x` will be
embedded in `get_custom_lambda` context.
Operator if `operator()()` is normal function then it should always
work. if is corutnie then it will break only if inner one could
outlive outer one. This depend on `lazy` destructor, if he cancel
request then everything would work fine. In case if it not cancel
inner corutine then we could still have UB becasue both corunite
context could be allocated in same block of memory with
`get_custom_lambda` (or this is forbidden in case like this?).


STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups