https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99361
Bug ID: 99361
Summary: "unused variable" warning on a used variable in
template lambda
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
The following code:
auto f() {
const auto x = 1;
return [] (auto) { return x; };
}
will emit unused variable warnings with "-std=c++20 -Wall" flags:
<source>: In function 'auto f()':
<source>:2:14: warning: variable 'x' set but not used
[-Wunused-but-set-variable]
2 | const auto x = 1;
|
godbolt: https://godbolt.org/z/d54j4G