From 0bff3a965022647fcdd17cc8f2217f5a2cd30b4c Mon Sep 17 00:00:00 2001 From: David Stone Date: Fri, 18 Feb 2022 05:54:33 -0800 Subject: [PATCH] Lambdas are not necessarily locals. This resolves DR48250. Differential Revision: https://reviews.llvm.org/D99134 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 +++- clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 2e8ddc8..237886c 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -6034,7 +6034,9 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, (ParentDependsOnArgs && (ParentDC->isFunctionOrMethod() || isa(ParentDC) || isa(ParentDC))) || - (isa(D) && cast(D)->isLambda())) { + (isa(D) && cast(D)->isLambda() && + cast(D)->getTemplateDepth() > + TemplateArgs.getNumRetainedOuterLevels())) { // D is a local of some kind. Look into the map of local // declarations to their instantiations. if (CurrentInstantiationScope) { diff --git a/clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp b/clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp index 13fe12a..a5410d2 100644 --- a/clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp +++ b/clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp @@ -39,3 +39,13 @@ void c2() { const auto lambda = [&](auto arg1) {}; [&](auto arg2) { lambda.operator()(arg2); }(0); } + +auto d = [](auto) {}; + +template +void d1(T x) { d.operator()(x); } + +void d2() { d1(0); } + +template int e1 = [](auto){ return T(); }.operator()(T()); +int e2 = e1; -- 2.7.4