[clang] [Clang][Sema] Fix lambdas mistakenly inheriting InImmediateFunctionContext (PR #232458)

Ferdinand Bachmann via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 16 01:51:14 PDT 2026


Ferdi265 wrote:

```c++
constexpr auto l = [] consteval {};
static_assert(
        +l
);
```

- the lambda declaration for `l` is consteval
- the unary + creates a `SynthesizedFunctionScope` for the synthesized operator
- the pushed expression evaluation context is `InImmediateFunctionContext` by default due to constant evaluation
- but this operator is not explicitly declared consteval, so `FD->isConsteval()` is false
- this causes `PushExpressionEvaluationContextForFunction` to set `InImmediateFunctionContext` to false
- this causes the wrong diagnostic

It looks like the lambda call operator must not inherit `InImmediateFunctionContext` from a parent context to avoid #183415, but other synthesized operators, such as the unary +, do need to inherit `InImmediateFunctionContext`. This will likely take a while to figure out properly.

https://github.com/llvm/llvm-project/pull/232458


More information about the cfe-commits mailing list