Skip to content

Commit 0bff3a9

Browse files
davidstoneErich Keane
authored andcommitted
Lambdas are not necessarily locals. This resolves DR48250.
Differential Revision: https://reviews.llvm.org/D99134
1 parent 6527b2a commit 0bff3a9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6034,7 +6034,9 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
60346034
(ParentDependsOnArgs && (ParentDC->isFunctionOrMethod() ||
60356035
isa<OMPDeclareReductionDecl>(ParentDC) ||
60366036
isa<OMPDeclareMapperDecl>(ParentDC))) ||
6037-
(isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda())) {
6037+
(isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda() &&
6038+
cast<CXXRecordDecl>(D)->getTemplateDepth() >
6039+
TemplateArgs.getNumRetainedOuterLevels())) {
60386040
// D is a local of some kind. Look into the map of local
60396041
// declarations to their instantiations.
60406042
if (CurrentInstantiationScope) {

clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ void c2() {
3939
const auto lambda = [&](auto arg1) {};
4040
[&](auto arg2) { lambda.operator()(arg2); }(0);
4141
}
42+
43+
auto d = [](auto) {};
44+
45+
template <typename T>
46+
void d1(T x) { d.operator()(x); }
47+
48+
void d2() { d1(0); }
49+
50+
template <typename T> int e1 = [](auto){ return T(); }.operator()(T());
51+
int e2 = e1<int>;

0 commit comments

Comments
 (0)