This is needed to fix https://github.com/llvm/llvm-project/issues/60155.
An assertion in tryCaptureVariable fails because SubstDefaultArgument pushes the context for the lambda's function operator, but the LambdaScopeInfo isn't being pushed to the stack.
It appears that the assertion started to fail in 4409a83c293537e22da046b54e9f69454cdd3dca, which delays instantiation of default arguments. By the time the default arguments are instantiated, which happens after inherited::TransformLambdaExpr is called, the lambda scope has already been popped.
If I'm understanding the issue correctly, the problem is that the lambda scope was created within the call to inherited::TransformLambdaExpr(E) above, but then popped upon return (and the copy created to outlive the call to Sema::ActOnFinishFunctionBody() destructed). A better solution then would be to modify TreeTransform::TransformLambdaExpr() to include this loop and dispatch transformation of the default argument via getDerived().transformLambdaDefaultArgument() (or similar). That seems like a straight forward refactor that might be useful elsewhere.