C++ Logo

std-proposals

Advanced search

Re: [std-proposals] sizeof lambda in an unevaluated context

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Tue, 25 Jun 2024 16:35:29 +0200
wt., 25 cze 2024 o 16:14 Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> napisaƂ(a):
>
> On Tuesday 25 June 2024 03:23:35 GMT-7 Frederick Virchanza Gotham via Std-
> Proposals wrote:
> > Do you not at least think that the following program should print the
> > same number out twice?
> >
> > https://godbolt.org/z/WTvfKb3dr
> >
> > It prints 1 for the first size, and 72 for the second size. Do you
> > think that's okay? Or should it be fixed?
>
> I think that's ok. First, even if what you had requested to be applied to the
> standard were there, it wouldn't apply here because the captures are not the
> same. The first lambda captures 9 integers by value, the second captures 9
> pointers. So how is this example relevant to the discussion?
>
> Second, the most likely reason is that the compiler performed a constant
> propagation in the first lambda, so the capture of 1 is actually zero and the
> captures aren't actually captures, but are baked into the code. I think this
> is an especially good idea and a very good reason to reject your proposal.
>

In some cases even if lambda has multiple captures it would be prefered if
size was `4` (or `8` for 64bit) if all objects could be accessible by
static offsets
and have the same lifetime. This could be beneficial for `[&]` and
make it a bit more ABI stable.

> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel DCAI Platform & System Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-06-25 14:35:44