C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 25 Jun 2024 07:14:21 -0700
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.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

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