[Bug c/71249] -Wswitch-unreachable false positive for a compound statement containing a used label

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue May 24 02:49:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71249

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Ah, right, my mistake.  But there is a false positive there, despite my initial
test case not demonstrating it.  Changing the first of the compound statement
to some other non-label statement such as a declaration shows that
(interestingly, the test case below only issues as warning with G++ and not
GCC).  It seems to me that to avoid the false positive the algorithm needs to
consider more than just the first statement.  It either needs to look for label
in the compound statement that can be reached from outside it, or it needs to
ignore declarations and other things that precede it and don't emit executable
code.

$ cat xxx.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc
-Wswitch-unreachable -xc++ xxx.c
int f (int i)
{
  switch (i) {
  { int j; foo: return i; };
  case 3: goto foo;
  }
  return i;
}

xxx.c: In function ‘int f(int)’:
xxx.c:4:25: warning: statement will never be executed [-Wswitch-unreachable]
   { int j; foo: return i; };
                         ^


More information about the Gcc-bugs mailing list