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++/12668] New: Strange warnings with -O1 -Wunreachable-code in 3.3.1,3.3.2,3.4


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Strange warnings with -O1 -Wunreachable-code in
                    3.3.1,3.3.2,3.4
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rmerkert at alphatech dot com
                CC: gcc-bugs at gcc dot gnu dot org

The following code produces a strange warning when compiled with
-Wunrechable-code and optimization:

cat > test.c <<EOF
inline void foo (int x)
{
   if (x!=0)
     x = x + 1;
}

int main ()
{
  foo(0);
/* if (0) { foo(1); } */  
  return 0;
}

EOF

gcc -O1 test.c -Wunreachable-code

The error message I get with both 3.3.1, 3.3.2, 3.4-20031001 is this:
test.c: In function `main':
test.c:4: warning: will never be executed

The message is somewhat misleading. I think it should either say something like:
test.c: In function 'foo':
test.c:4 warning: will never be executed

or 

test.c: In function 'main':
test.8: warning: will never be executed


By the way, if compiled with g++, there will be an extra empty line the output:
test.c: In function `main':

test.c:4: warning: will never be executed

and if you uncomment line 10 you'll get 4 warnings with 3.4 and 3 warnings with
3.3 and they are not helpful (gcc-3.3 doesn't even tell me about line 10).

I'm actually not sure I want the warning in this case - I really want the
compiler to tell me that a section of code cannot possibly be reached such as
"while (false) {}"


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