https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110707
Bug ID: 110707
Summary: unused-but-set-variable in static lambda with deduced
parameter
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: chris0cotter at gmail dot com
Target Milestone: ---
With GCC-13.1 using `-std=c++20 -Wall`, the following code causes an
unused-but-set-variable warning for `f1` being unused.
https://godbolt.org/z/5vfEd7vr5
int foo() {
static auto f1 = [](int a) { return a;}; // warning: variable 'f1' set but
not used [-Wunused-but-set-variable]
static auto f2 = [](auto s) -> int { return f1(s); };
return f2(0);
}
The warning disappears if I replace `auto s` with `int s`, or if I remove the
return type from the second lambda ` -> int`.