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

Ivan Murashko via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 10 08:20:57 PDT 2025


================
@@ -8496,6 +8498,21 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
                 ->ShadowingDecls.push_back({D, VD});
             return;
           }
+        } else if (isa<BindingDecl>(ShadowedDecl)) {
+          // Apply lambda capture logic only when D is actually a lambda capture
+          if (isa<VarDecl>(D) && cast<VarDecl>(D)->isInitCapture()) {
+            if (RD->getLambdaCaptureDefault() == LCD_None) {
+              // BindingDecls cannot be explicitly captured, so always treat as
+              // uncaptured
+              WarningDiag = diag::warn_decl_shadow_uncaptured_local;
+            } else {
+              // Same deferred handling as VarDecl
+              cast<LambdaScopeInfo>(getCurFunction())
+                  ->ShadowingDecls.push_back({D, ShadowedDecl});
+              return;
+            }
+          }
+          // For non-init-capture cases, fall through to regular shadow logic
----------------
ivanmurashko wrote:

Consolidated `VarDecl` and `BindingDecl` handling using `ValueDecl` at 27fc9b7095e6ab993782e121e1ff1a3776b2ab0a

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


More information about the cfe-commits mailing list