[PATCH] D140838: [clang] fix crash on generic lambda with lambda in decltype

Vincent Hong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 1 22:24:30 PST 2023


v1nh1shungry created this revision.
v1nh1shungry added reviewers: aaron.ballman, shafik.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Relevant issue: https://github.com/llvm/llvm-project/issues/59771

During the instantiation of a generic lambda, a non-generic lambda in
the trailing `decltype` is a `DeclContext` but not a dependent context,
so we shouldn't call `PerformDependentDiagnostics` on it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140838

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp


Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===================================================================
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -144,3 +144,7 @@
 using d = decltype(sizeof([] static { return 0; }));
 
 }
+
+namespace lambda_in_trailing_decltype {
+auto x = ([](auto) -> decltype([] {}()) {}(0), 2);
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1230,7 +1230,7 @@
 
       // We recreated a local declaration, but not by instantiating it. There
       // may be pending dependent diagnostics to produce.
-      if (auto *DC = dyn_cast<DeclContext>(Old))
+      if (auto *DC = dyn_cast<DeclContext>(Old); DC && DC->isDependentContext())
         SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140838.485843.patch
Type: text/x-patch
Size: 965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230102/a486ddeb/attachment.bin>


More information about the cfe-commits mailing list