https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Bug ID: 96311 Summary: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tilkax at gmail dot com Target Milestone: --- Using gcc version 11.0.0 20200723, this code: void foo() { constexpr int used = 0; [](auto unused) { return used; }; } triggers an incorrect warning: <source>:3:19: warning: variable 'used' set but not used [-Wunused-but-set-variable] 3 | constexpr int used = 0; | ^~~~ It doesn't matter whether the lambda is called but it does need to be a generic lambda to trigger the incorrect warning. Also, both the lambda parameter as well as the lambda itself are unused here but don't trigger any warnings :/