Skip to content

Commit

Permalink
CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LYP951018 committed Jul 6, 2024
1 parent a997ae7 commit 85730ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ Bug Fixes to C++ Support
- Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
- Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307),
(#GH88081), (#GH89496), (#GH90669) and (#GH91633).
- Fixed a crash in constraint instantiation under nested lambdas with dependent parameters.
- Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368).
- Clang now instantiates local constexpr functions eagerly for constant evaluators. (#GH35052), (#GH94849)
- Fixed a failed assertion when attempting to convert an integer representing the difference
Expand Down
25 changes: 15 additions & 10 deletions clang/lib/Sema/SemaLambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2390,21 +2390,26 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::

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));
FDPattern =
dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext(FDPattern));
FD = dyn_cast<FunctionDecl>(getLambdaAwareParentOfDeclContext(FD));

if (!Current.first || !Current.second)
if (!FDPattern || !FD)
break;

ParentInstantiations.push_back(Current);
ParentInstantiations.emplace_back(FDPattern, FD);
}

for (const auto &[Pattern, Inst] : llvm::reverse(ParentInstantiations)) {
SemaRef.addInstantiatedParametersToScope(Inst, Pattern, Scope, MLTAL);
SemaRef.addInstantiatedLocalVarsToScope(Inst, Pattern, Scope);
// Add instantiated parameters and local vars to scopes, starting from the
// outermost lambda to the innermost lambda. This ordering ensures that
// parameters in inner lambdas can correctly depend on those defined
// in outer lambdas, e.g. auto L = [](auto... x) {
// return [](decltype(x)... y) { }; // `y` depends on `x`
// };

for (const auto &[FDPattern, FD] : llvm::reverse(ParentInstantiations)) {
SemaRef.addInstantiatedParametersToScope(FD, FDPattern, Scope, MLTAL);
SemaRef.addInstantiatedLocalVarsToScope(FD, FDPattern, Scope);
}
}

0 comments on commit 85730ed

Please sign in to comment.