Question
Does GCC's -Wshadow warn on lambda captures that shadow outer variables?
Ari River
0 reputation · 16 Jul 2025, 18:04 UTC
52.5K views0
Goal
The goal is to determine whether the -Wshadow option should emit a warning when a C++ lambda capture introduces a name that hides an outer variable.
Constraints
The GCC manual states that -Wshadow applies only to C, yet GCC 10 produces a warning for such lambda captures while GCC 12 does not, and the bug tracker lists this discrepancy as an open issue.
Questions
- Which GCC versions emit the warning for lambda captures that shadow outer variables?
- Is the -Wshadow warning intended for C++ code or only for C?
- How does -Wextra interact with -Wshadow to produce duplicate warnings for the same shadowed name?