This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/20911] New: Erroneous unreachable code warning


#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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]