https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128062
Bug ID: 128062
Summary: wrong fall through with cases defined from a macro
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
#define case23 case 2: case 3
int f(int a, int b)
{
int c = 0;
switch (a)
{
case 0:
if (b)
c = 1;
/* FALLTHRU */
case23:
case 1:
c+=2;
break;
default:
c++;
}
return c;
}
```
This gives the following warning:
<source>: In function 'int f(int, int)':
<source>:8:7: warning: this statement may fall through
[-Wimplicit-fallthrough=]
8 | if (b)
| ^~
<source>:1:16: note: here
1 | #define case23 case 2: case 3
| ^~~~
<source>:11:5: note: in expansion of macro 'case23'
11 | case23:
| ^~~~~~
But that is wrong as there is a comment for the FALLTHRU . If we swap around
`case 1:` and `case23:` there is no warning.
This was reduced from GCC code I was working on. This happens with both C and
C++ front-end.