[all-commits] [llvm/llvm-project] 068fe2: [Clang] Rebuild lambda captures in default member ...
Yuxuan Chen via All-commits
all-commits at lists.llvm.org
Wed Jun 24 08:37:53 PDT 2026
Branch: refs/heads/users/yuxuanchen1997/fix-cwg1815-lambda-capture-cleanup
Home: https://github.com/llvm/llvm-project
Commit: 068fe29bf343002213af297972167c641c50df28
https://github.com/llvm/llvm-project/commit/068fe29bf343002213af297972167c641c50df28
Author: Yuxuan Chen <ych at meta.com>
Date: 2026-06-24 (Wed, 24 Jun 2026)
Changed paths:
M clang/lib/Sema/SemaExpr.cpp
A clang/test/CodeGenCXX/gh196469-default-member-init-lambda-cleanup.cpp
A clang/test/SemaCXX/gh196469-default-member-init-lambda-capture.cpp
Log Message:
-----------
[Clang] Rebuild lambda captures in default member initializers
Fixes https://github.com/llvm/llvm-project/issues/196469
Since the CWG1815 implementation, `InitListChecker` rebuilds a default
member initializer at its point of use in aggregate initialization. The
rebuild uses the `EnsureImmediateInvocationInDefaultArgs` tree
transform, where `TransformCXXBindTemporaryExpr` strips
`CXXBindTemporaryExpr` nodes, relying on the subexpression's rebuild to
re-create the temporary binding: every `Rebuild*` path funnels through
`Sema::MaybeBindToTemporary`, which also re-registers the cleanup in
the current evaluation context.
However, the transform overrides `TransformLambdaExpr` to return the
closure unchanged because the lambda body is not a subexpression. That
skips the `MaybeBindToTemporary` call that `BuildLambdaExpr` ends with.
The rebuilt initializer then lacks both the `CXXBindTemporaryExpr`
around the closure and the `ExprWithCleanups` marker, so CodeGen never
emits the closure's destructor and init-captured members leak.
Lambda init-captures are different from the body: their initializers are
evaluated in the enclosing context and can also contain immediate
invocations that need to be rebuilt at the default-initializer use site.
Visit init-captures when deciding whether the default initializer needs
rebuilding, and rebuild the lambda shell/captures while using
`SkipLambdaBody` to leave the body itself untouched. Rebuilding the
lambda this way also restores the closure temporary binding and cleanup
through `BuildLambdaExpr`.
Co-Authored-By: GPT-5.5 <noreply at openai.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list