https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91915
Bug ID: 91915
Summary: New warning for duplicate if condition in
if-elseif-elseif chain
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
Blocks: 87403
Target Milestone: ---
As seen here:
cat /tmp/warn.c
int global;
void bar();
int foo(int argc)
{
if (argc == 1)
bar ();
else if (argc == 2) {
global += 1;
}
else if (argc == 1)
{
bar ();
bar ();
}
return 0;
}
int main222(int argc)
{
switch (argc)
{
case 1:
bar ();
break;
case 2:
global += 1;
return 0;
case 1:
bar ();
bar ();
break;
default:
break;
}
return 0;
}
We want about duplicate switch cases:
gcc /tmp/warn.c
/tmp/warn.c: In function ‘main222’:
/tmp/warn.c:30:5: error: duplicate case value
30 | case 1:
| ^~~~
/tmp/warn.c:24:5: note: previously used here
24 | case 1:
| ^~~~
and I think it can be handy to the same for the if-elseif chains that are
semantically equal to the switch statement.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning