[all-commits] [llvm/llvm-project] dc31f0: [Clang] Rebuild lambda capture initializers in def...

Yuxuan Chen via All-commits all-commits at lists.llvm.org
Thu Jun 25 10:56:22 PDT 2026


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

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    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
    M clang/test/SemaCXX/source_location.cpp

  Log Message:
  -----------
  [Clang] Rebuild lambda capture initializers 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 recreate the temporary binding and re-register cleanups in the current evaluation context.

However, the transform overrides TransformLambdaExpr because the lambda body is not a subexpression. Returning the original lambda unchanged skips the MaybeBindToTemporary call that BuildLambdaExpr would normally perform, so the rebuilt initializer can lack the closure temporary binding and cleanup marker. CodeGen then misses the closure destructor and init-captured members can leak.

Lambda init-capture initializers are evaluated in the enclosing context and can also contain immediate invocations or source-location expressions that need to be rebuilt at the default-initializer use site. Rebuild those initializer expressions without rebuilding the closure type, capture declarations, or body, so body references to init-capture declarations remain valid. When a capture initializer changes, create a replacement LambdaExpr that shares the existing closure and body, then bind the lambda temporary explicitly to restore cleanup emission.

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