Bug 112309

Summary: enhancement: extra flags to let -Wshadow skip if..else and lambda blocks
Product: gcc Reporter: Joachim Wuttke <j.wuttke>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: webrown.cpp
Priority: P3 Keywords: diagnostic
Version: 14.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79328
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 87403    

Description Joachim Wuttke 2023-10-31 10:48:21 UTC
Suggestion: add a flag -Wnoshadow-ifelse to prevent -Wshadow from reporting shadowing in "else if" constructs like

if (auto* p = dynamic_cast<A>(x))
   ...
else if (auto* p = dynamic_cast<B>(x))
   ...
else if (auto* p = dynamic_cast<C>(x))
   ...


A similar approach (-Wnoshadow-lambda) could help to resolve https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79328.