================ @@ -8508,18 +8511,29 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, return; } } - if (const auto *VD = dyn_cast<VarDecl>(ShadowedDecl); - VD && VD->hasLocalStorage()) { - // A variable can't shadow a local variable in an enclosing scope, if - // they are separated by a non-capturing declaration context. - for (DeclContext *ParentDC = NewDC; - ParentDC && !ParentDC->Equals(OldDC); - ParentDC = getLambdaAwareParentOfDeclContext(ParentDC)) { - // Only block literals, captured statements, and lambda expressions - // can capture; other scopes don't. - if (!isa<BlockDecl>(ParentDC) && !isa<CapturedDecl>(ParentDC) && - !isLambdaCallOperator(ParentDC)) { - return; + // Apply scoping logic to both VarDecl and BindingDecl with local storage + if (isa<VarDecl, BindingDecl>(ShadowedDecl)) { + bool HasLocalStorage = false; + if (const auto *VD = dyn_cast<VarDecl>(ShadowedDecl)) { + HasLocalStorage = VD->hasLocalStorage(); + } else if (const auto *BD = dyn_cast<BindingDecl>(ShadowedDecl)) { + HasLocalStorage = + cast<VarDecl>(BD->getDecomposedDecl())->hasLocalStorage(); + } ---------------- Fznamznon wrote:
```suggestion if (const auto *VD = dyn_cast<VarDecl>(ShadowedDecl)) HasLocalStorage = VD->hasLocalStorage(); else if (const auto *BD = dyn_cast<BindingDecl>(ShadowedDecl)) HasLocalStorage = cast<VarDecl>(BD->getDecomposedDecl())->hasLocalStorage(); ``` LLVM codestyle suggests to avoid curleys for single-statement scopes. https://github.com/llvm/llvm-project/pull/157667 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits