public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/20911] New: Erroneous unreachable code warning
@ 2005-04-08 22:28 rici at ricilake dot net
  2005-04-08 22:32 ` [Bug middle-end/20911] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: rici at ricilake dot net @ 2005-04-08 22:28 UTC (permalink / raw)
  To: gcc-bugs

#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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug middle-end/20911] Erroneous unreachable code warning
  2005-04-08 22:28 [Bug c/20911] New: Erroneous unreachable code warning rici at ricilake dot net
@ 2005-04-08 22:32 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-08 22:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-08 22:32 -------
Fixed in 4.0.0 and above.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|c                           |middle-end
           Keywords|                            |diagnostic
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20911


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-04-08 22:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-08 22:28 [Bug c/20911] New: Erroneous unreachable code warning rici at ricilake dot net
2005-04-08 22:32 ` [Bug middle-end/20911] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).