Skip to content

Commit a997ae7

Browse files
committed
Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII.
1 parent 7782de8 commit a997ae7

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

clang/lib/Sema/SemaLambda.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
23792379

23802380
SemaRef.RebuildLambdaScopeInfo(cast<CXXMethodDecl>(FD));
23812381

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;
23852385

2386-
FunctionDecl *ParentFD = FD;
2387-
while (ShouldAddDeclsFromParentScope) {
2386+
SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);
23882387

2389-
ParentFD =
2390-
dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext(ParentFD));
2391-
Pattern =
2392-
dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext(Pattern));
2388+
if (!ShouldAddDeclsFromParentScope)
2389+
return;
23932390

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));
23962399

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);
24002409
}
24012410
}

clang/test/SemaTemplate/concepts-lambda.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,17 @@ concept D = []<C T = int>() { return true; }();
237237
D auto x = 0;
238238

239239
} // namespace GH93821
240+
241+
namespace dependent_param_concept {
242+
template <typename... Ts> void sink(Ts...) {}
243+
void dependent_param() {
244+
auto L = [](auto... x) {
245+
return [](decltype(x)... y) {
246+
return [](int z)
247+
requires requires { sink(y..., z); }
248+
{};
249+
};
250+
};
251+
L(0, 1)(1, 2)(1);
252+
}
253+
} // namespace dependent_param_concept

0 commit comments

Comments
 (0)