[clang] [Clang] Do not inherit immediate-function context in lambda bodies (PR #214002)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 4 09:48:06 PDT 2026


https://github.com/term-est created https://github.com/llvm/llvm-project/pull/214002

Fixes: #169139

Lambda bodies are not subexpressions of their enclosing lambda-expression, so they should not inherit its immediate-function context.

This prevents consteval calls inside lambdas used as NTTPs from reaching CodeGen as runtime calls.

>From fcba5fc86df76161420027750f6fca5caae34e67 Mon Sep 17 00:00:00 2001
From: term-est <eurasia.sely at gmail.com>
Date: Tue, 4 Aug 2026 19:23:57 +0300
Subject: [PATCH] [clang] Linker regression with lambda NTTP containing
 consteval function call  #169139

---
 clang/lib/Sema/SemaLambda.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index bbe93f6ab8a40..91016e3523387 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1601,6 +1601,9 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
   // cleanups from the enclosing full-expression.
   PushExpressionEvaluationContextForFunction(
       ExpressionEvaluationContext::PotentiallyEvaluated, LSI->CallOperator);
+
+  currentEvaluationContext().InImmediateFunctionContext =
+      LSI->CallOperator->isConsteval();
 }
 
 void Sema::ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope,



More information about the cfe-commits mailing list