[clang] [clang] Don't use `VarDecl` of local variables as `ManglingContextDecl` for lambdas (PR #179035)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 31 08:53:50 PST 2026


================
@@ -294,6 +294,14 @@ Sema::getCurrentMangleNumberContext(const DeclContext *DC) {
   bool IsInNonspecializedTemplate =
       inTemplateInstantiation() || CurContext->isDependentContext();
 
+  // If we must allocate mangling numbers but the `ManglingContextDecl`
+  // is a local variable, use the `DeclContext` containing the lambda expression
+  // instead.
+  if (ManglingContextDecl)
+    if (VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl);
----------------
cor3ntin wrote:

```suggestion
  if (VarDecl *Var = dyn_cast_or_null<VarDecl>(ManglingContextDecl);
```

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


More information about the cfe-commits mailing list