@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
2379
2379
2380
2380
SemaRef.RebuildLambdaScopeInfo (cast<CXXMethodDecl>(FD));
2381
2381
2382
- FunctionDecl *Pattern = getPatternFunctionDecl (FD);
2383
- if (Pattern) {
2384
- SemaRef. addInstantiatedCapturesToScope (FD, Pattern, Scope, MLTAL) ;
2382
+ FunctionDecl *FDPattern = getPatternFunctionDecl (FD);
2383
+ if (!FDPattern)
2384
+ return ;
2385
2385
2386
- FunctionDecl *ParentFD = FD;
2387
- while (ShouldAddDeclsFromParentScope) {
2386
+ SemaRef.addInstantiatedCapturesToScope (FD, FDPattern, Scope, MLTAL);
2388
2387
2389
- ParentFD =
2390
- dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext (ParentFD));
2391
- Pattern =
2392
- dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext (Pattern));
2388
+ if (!ShouldAddDeclsFromParentScope)
2389
+ return ;
2393
2390
2394
- if (!ParentFD || !Pattern)
2395
- break ;
2391
+ llvm::SmallVector<std::pair<FunctionDecl *, FunctionDecl *>, 4 >
2392
+ ParentInstantiations;
2393
+ std::pair<FunctionDecl *, FunctionDecl *> Current = {FDPattern, FD};
2394
+ while (true ) {
2395
+ Current.first = dyn_cast<FunctionDecl>(
2396
+ getLambdaAwareParentOfDeclContext (Current.first ));
2397
+ Current.second = dyn_cast<FunctionDecl>(
2398
+ getLambdaAwareParentOfDeclContext (Current.second ));
2396
2399
2397
- SemaRef.addInstantiatedParametersToScope (ParentFD, Pattern, Scope, MLTAL);
2398
- SemaRef.addInstantiatedLocalVarsToScope (ParentFD, Pattern, Scope);
2399
- }
2400
+ if (!Current.first || !Current.second )
2401
+ break ;
2402
+
2403
+ ParentInstantiations.push_back (Current);
2404
+ }
2405
+
2406
+ for (const auto &[Pattern, Inst] : llvm::reverse (ParentInstantiations)) {
2407
+ SemaRef.addInstantiatedParametersToScope (Inst, Pattern, Scope, MLTAL);
2408
+ SemaRef.addInstantiatedLocalVarsToScope (Inst, Pattern, Scope);
2400
2409
}
2401
2410
}
0 commit comments