[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 6 06:39:42 PDT 2024


================
@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
 
   SemaRef.RebuildLambdaScopeInfo(cast<CXXMethodDecl>(FD));
 
-  FunctionDecl *Pattern = getPatternFunctionDecl(FD);
-  if (Pattern) {
-    SemaRef.addInstantiatedCapturesToScope(FD, Pattern, Scope, MLTAL);
+  FunctionDecl *FDPattern = getPatternFunctionDecl(FD);
+  if (!FDPattern)
+    return;
 
-    FunctionDecl *ParentFD = FD;
-    while (ShouldAddDeclsFromParentScope) {
+  SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);
 
-      ParentFD =
-          dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext(ParentFD));
-      Pattern =
-          dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext(Pattern));
+  if (!ShouldAddDeclsFromParentScope)
+    return;
 
-      if (!ParentFD || !Pattern)
-        break;
+  llvm::SmallVector<std::pair<FunctionDecl *, FunctionDecl *>, 4>
+      ParentInstantiations;
+  std::pair<FunctionDecl *, FunctionDecl *> Current = {FDPattern, FD};
+  while (true) {
+    Current.first = dyn_cast<FunctionDecl>(
+        getLambdaAwareParentOfDeclContext(Current.first));
+    Current.second = dyn_cast<FunctionDecl>(
+        getLambdaAwareParentOfDeclContext(Current.second));
----------------
cor3ntin wrote:

Alternatively, only form the pair when emplacing in the vector.

https://github.com/llvm/llvm-project/pull/97215


More information about the cfe-commits mailing list