[all-commits] [llvm/llvm-project] 190653: [Clang] Rebind the closure temporary when rebuildi...

Yuxuan Chen via All-commits all-commits at lists.llvm.org
Wed Jun 10 08:00:34 PDT 2026


  Branch: refs/heads/users/yuxuanchen1997/fix-cwg1815-lambda-capture-cleanup
  Home:   https://github.com/llvm/llvm-project
  Commit: 190653df6b4480e824a079a27089ed847fcb7fdd
      https://github.com/llvm/llvm-project/commit/190653df6b4480e824a079a27089ed847fcb7fdd
  Author: Yuxuan Chen <ych at meta.com>
  Date:   2026-06-10 (Wed, 10 Jun 2026)

  Changed paths:
    M clang/lib/Sema/SemaExpr.cpp
    A clang/test/CodeGenCXX/gh196469-default-member-init-lambda-cleanup.cpp

  Log Message:
  -----------
  [Clang] Rebind the closure temporary when rebuilding 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 (the body is not a subexpression), skipping 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.

Restore the side effect in the override: re-bind the closure to a
temporary, exactly as building the lambda would have. This is a no-op
for trivially destructible closures.

Co-Authored-By: Claude Fable 5 <noreply at anthropic.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