#include <stdlib.h>
#include <stdio.h>
void print_joined (const char *first, const char *delim, const char *last,
const char *def,
char **list) {
switch (*list == NULL) {
for (; *list; ++list) {
printf("%s", delim);
if (0) {
case 0:
printf("%s", first);
}
printf("%s", *list);
}
printf("%s", last);
break;
default:
printf("%s", def);
break;
}
}
int main (int argc, char **argv) {
print_joined("(", ", ", ")", "nil", argv + 1);
puts("");
return 0;
}
---------------
OK, it's an outrageous bit of code. But it's legal and it works. However, gcc
3.3.3 reports
join.c: In function `print_joined':
join.c:8: warning: unreachable code at beginning of switch statement
with -O{1,2}
and
join.c: In function `main':
join.c:8: warning: unreachable code at beginning of switch statement
join.c: In function `print_joined':
join.c:8: warning: unreachable code at beginning of switch statement
with -O{3,4,5}
The code is clearly reachable; running the program reaches it:
[EMAIL PROTECTED]:~/src$ ./join
nil
[EMAIL PROTECTED]:~/src$ ./join a
(a)
[EMAIL PROTECTED]:~/src$ ./join a b
(a, b)
[EMAIL PROTECTED]:~/src$ ./join a b c
(a, b, c)
--
Summary: Erroneous unreachable code warning
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rici at ricilake dot net
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20911