https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96571
Bug ID: 96571
Summary: Bad "set but not used" warning with _Generic
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jsm28 at gcc dot gnu.org
Target Milestone: ---
Compile the following with -Wall:
enum E { V };
int
f (void)
{
enum E v;
return _Generic (v, enum E : 0);
}
This produces a warning:
t.c: In function 'f':
t.c:6:10: warning: variable 'v' set but not used [-Wunused-but-set-variable]
6 | enum E v;
| ^
It's arguable whether the variable is "used" when it's only referenced in the
controlling expression of _Generic (so never actually evaluated), but it's
certainly not set.