[PATCH] D99134: Lambdas are not necessarily locals. This resolves DR48250.

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 18 06:11:51 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0bff3a965022: Lambdas are not necessarily locals. This resolves DR48250. (authored by davidstone, committed by erichkeane).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99134/new/

https://reviews.llvm.org/D99134

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


Index: clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp
===================================================================
--- clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp
+++ clang/test/SemaCXX/lambdas-implicit-explicit-template.cpp
@@ -39,3 +39,13 @@
   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>;
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6034,7 +6034,9 @@
       (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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99134.409919.patch
Type: text/x-patch
Size: 1433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220218/8c341572/attachment.bin>


More information about the cfe-commits mailing list