[llvm-branch-commits] [clang] f7007c5 - Lambdas are not necessarily locals. This resolves DR48250.

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Mar 8 20:44:35 PST 2022


Author: David Stone
Date: 2022-03-08T20:41:20-08:00
New Revision: f7007c570a216c0fa87b863733a1011bdb2ff9ca

URL: https://github.com/llvm/llvm-project/commit/f7007c570a216c0fa87b863733a1011bdb2ff9ca
DIFF: https://github.com/llvm/llvm-project/commit/f7007c570a216c0fa87b863733a1011bdb2ff9ca.diff

LOG: Lambdas are not necessarily locals. This resolves DR48250.

Differential Revision: https://reviews.llvm.org/D99134

(cherry picked from commit 0bff3a965022647fcdd17cc8f2217f5a2cd30b4c)

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 1da0dfec3f230..467372c71496a 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6012,7 +6012,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) {

diff  --git a/clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp b/clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp
index 13fe12abe9e9d..a5410d2aed597 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 <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>;


        


More information about the llvm-branch-commits mailing list