Lambdas are not necessarily locals. This resolves DR48250.

Differential Revision: https://reviews.llvm.org/D99134
This commit is contained in:
David Stone 2022-02-18 05:54:33 -08:00 committed by Erich Keane
parent 6527b2a4d5
commit 0bff3a9650
2 changed files with 13 additions and 1 deletions

View File

@ -6034,7 +6034,9 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
(ParentDependsOnArgs && (ParentDC->isFunctionOrMethod() ||
isa<OMPDeclareReductionDecl>(ParentDC) ||
isa<OMPDeclareMapperDecl>(ParentDC))) ||
(isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda())) {
(isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda() &&
cast<CXXRecordDecl>(D)->getTemplateDepth() >
TemplateArgs.getNumRetainedOuterLevels())) {
// D is a local of some kind. Look into the map of local
// declarations to their instantiations.
if (CurrentInstantiationScope) {

View File

@ -39,3 +39,13 @@ void c2() {
const auto lambda = [&](auto arg1) {};
[&](auto arg2) { lambda.operator()(arg2); }(0);
}
auto d = [](auto) {};
template <typename T>
void d1(T x) { d.operator()(x); }
void d2() { d1(0); }
template <typename T> int e1 = [](auto){ return T(); }.operator()(T());
int e2 = e1<int>;