[clang] [Clang] Fix a wrong diagnostic about a local variable inside a lambda in unevaluated context need capture (PR #165098)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 27 08:08:54 PDT 2025


================
@@ -7061,8 +7061,15 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
     // anonymous unions in class templates).
   }
 
-  if (!ParentDependsOnArgs)
+  if (!ParentDependsOnArgs) {
+    if (auto Found =
+            CurrentInstantiationScope
+                ? CurrentInstantiationScope->getInstantiationOfIfExists(D)
+                : nullptr) {
+      return cast<NamedDecl>(Found->dyn_cast<Decl *>());
----------------
Fznamznon wrote:

Using of `dyn_cast` is strange here IMO, since the around `cast` doesn't expect null. If that is always a Decl there, we probably need to use `get` here.

https://github.com/llvm/llvm-project/pull/165098


More information about the cfe-commits mailing list