================
@@ -14636,6 +14645,20 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr 
*E) {
                                     /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // Parts other than the capture e.g. the lambda body might still contain a
+  // pattern that an outer fold expression would expand.
+  //
+  // We don't have a way to propagate up the ContainsUnexpandedParameterPack
+  // flag from a Stmt, so we have to revisit the lambda.
+  if (!LSICopy.ContainsUnexpandedParameterPack) {
+    llvm::SmallVector<UnexpandedParameterPack> UnexpandedPacks;
+    getSema().collectUnexpandedParameterPacksFromLambda(NewCallOperator,
+                                                        UnexpandedPacks);
+    // FIXME: Should we call Sema::DiagnoseUnexpandedParameterPacks() instead?
+    // Unfortunately, that requires the LambdaScopeInfo to exist, which has 
been
+    // removed by ActOnFinishFunctionBody().
+    LSICopy.ContainsUnexpandedParameterPack = !UnexpandedPacks.empty();
+  }
----------------
mizvekov wrote:

I am not sure I understand why we would need to call 
`Sema::DiagnoseUnexpandedParameterPacks` here.

I think we should be able to diagnose all unexpanded parameter packs during the 
initial lambda parsing, so what gives?

Also, I am not sure what you mean by leaving it as an NFC.

Regardless, you have a copy of the LSI here, so what would stop you from 
pushing a new Lambda Scope and copying this LSI back into it? Something like:

```C++
  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
  *LSI = LSICopy;
  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
```

This is obviously an ugly hack, but I don't think the solution is to simply 
teach `ActOnFinishFunctionBody` not to pop the function scope.

See this FIXME for a potentially more comprehensive fix: 
https://github.com/llvm/llvm-project/blob/77ac07444d32668d5826ef27c24180fb10425213/clang/lib/Sema/TreeTransform.h#L14648

https://github.com/llvm/llvm-project/pull/86265
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to