https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117536
Bug ID: 117536 Summary: -Wshadow generates an incorrect warning with some usages of immediately invoked lambdas Product: gcc Version: 14.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: justus at opentransactions dot org Target Milestone: --- struct my_type {}; my_type get_value(); void init_value(my_type&); int main() { const auto my_var = [] { auto my_var = get_value(); init_value(my_var); return my_var; }(); return 0; } <source>: In lambda function: <source>:9:14: error: declaration of 'my_var' shadows a previous local [-Werror=shadow] 9 | auto my_var = get_value(); | ^~~~~~ This is a bogus warning because neither usage of my_var is in scope at the same time. The scope for the other my_var doesn't begin until the scope of all the variables in the immediately-invoked lambda ends.