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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 12 08:13:31 PST 2025


================
@@ -7061,8 +7061,17 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
     // anonymous unions in class templates).
   }
 
-  if (!ParentDependsOnArgs)
+  if (!ParentDependsOnArgs) {
+    if (CurrentInstantiationScope) {
+      if (llvm::PointerUnion<
+              Decl *, LocalInstantiationScope::DeclArgumentPack *> *Found =
+              CurrentInstantiationScope->getInstantiationOfIfExists(D)) {
+        if (Decl *FD = Found->dyn_cast<Decl *>())
----------------
erichkeane wrote:

it seems to me that this is a problem not with getting the current instantiation, but with how we determine that 'ParentDependsOnArgs'.  I would imagine that the calculation there is incorrect for the lambdas, not trying to do a fixup here.

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


More information about the cfe-commits mailing list