[clang] [Clang] Rebuild lambda captures in default member initializers while skipping body (PR #196597)

Yuxuan Chen via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 24 11:46:26 PDT 2026


================
@@ -5724,9 +5710,17 @@ struct EnsureImmediateInvocationInDefaultArgs
 
   // Lambda can only have immediate invocations in the default
   // args of their parameters, which is transformed upon calling the closure.
-  // The body is not a subexpression, so we have nothing to do.
+  // The body is not a subexpression, so we do not transform the lambda
+  // itself. However, the closure object is returned without rebuilding it,
+  // so we must redo the effects building a lambda has on the enclosing
+  // context: any CXXBindTemporaryExpr around it has been dropped by
+  // TransformCXXBindTemporaryExpr, and the enclosing context must be
+  // marked as requiring cleanups for the closure's destructor to be run
+  // at the end of the full-expression.
   // FIXME: Immediate calls in capture initializers should be transformed.
-  ExprResult TransformLambdaExpr(LambdaExpr *E) { return E; }
+  ExprResult TransformLambdaExpr(LambdaExpr *E) {
+    return SemaRef.MaybeBindToTemporary(E);
----------------
yuxuanchen1997 wrote:

Thanks. Let me see if it makes sense to file another issue for this. I want to properly scope the fix for this issue at hand. 

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


More information about the cfe-commits mailing list