[clang] [clang][Sema] Fix false positive -Wshadow with structured binding captures (PR #157667)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 11 02:52:04 PDT 2025


================
@@ -8479,8 +8479,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
   if (isa<VarDecl>(D) && NewDC && isa<CXXMethodDecl>(NewDC)) {
     if (const auto *RD = dyn_cast<CXXRecordDecl>(NewDC->getParent())) {
       if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
-        if (const auto *VD = dyn_cast<VarDecl>(ShadowedDecl)) {
+        // Handle both VarDecl and BindingDecl in lambda contexts
+        if (isa<VarDecl, BindingDecl>(ShadowedDecl)) {
+          const auto *VD = cast<ValueDecl>(ShadowedDecl);
           const auto *LSI = cast<LambdaScopeInfo>(getCurFunction());
+
----------------
Fznamznon wrote:

```suggestion
```

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


More information about the cfe-commits mailing list