Spurious warning in gcc SVN trunk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just for kicks, I pulled a copy of SVN trunk today, built it, and tried
compiling some existing code. While it caught a number of problems that
previous versions did not, it also reported a couple of cases that seem
spurious. Here's a small example:

> #include <stdlib.h>
> #include <stdio.h>
> 
> int main(int argc, char **argv)
> {
>         switch (argc) {
>         case 0:
>         {
>                 char *foo = malloc(1);
>                 if (!foo)
>         TEST_LABEL:
>                 {
>                         printf("test\n");
>                         return 0;
>                 }
>                 free(foo);
>                 break;
>         }
>         case 1:
>         {
>                 char *foo = "xyz";
>                 if (argv[0]) {
>                         goto TEST_LABEL;
>                 }
>                 printf(foo);
>                 break;
>         }
>         }
>         return 0;
> }

Compiling this as follows:

> $ ~/gcc-trunk/bin/gcc -o test test.c -Wall
> test.c: In function ‘main’:
> test.c:23:4: warning: jump skips variable initialization
> test.c:11:2: note: label ‘TEST_LABEL’ defined here
> test.c:9:9: note: ‘foo’ declared here

While this warning is completely accurate, it's also spurious, because
the code that will execute after the jump to TEST_LABEL does not
reference the local variable 'foo' in the target block at all.

Now, I don't expect anyone to like this code... I've already fixed it up
to not be so horrifically bad, but it's still perfectly valid and should
not generate such a warning. Comments?

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kpfleming@xxxxxxxxxx
Check us out at www.digium.com & www.asterisk.org



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux