This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/20911] New: Erroneous unreachable code warning
- From: "rici at ricilake dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Apr 2005 22:28:00 -0000
- Subject: [Bug c/20911] New: Erroneous unreachable code warning
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
#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:
rlake@freeb:~/src$ ./join
nil
rlake@freeb:~/src$ ./join a
(a)
rlake@freeb:~/src$ ./join a b
(a, b)
rlake@freeb:~/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