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



             Bug #: 54804

           Summary: -Wuninitialized fails to warn about uninitialized

                    local union

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: egg...@gnu.org





This problem stems from a proposed change to Bison to work

around a GCC bug.  I'd rather get the GCC bug fixed, so I'm

filing this bug report.



Bison-generated parsers currently contain code that GCC incorrectly

generates a -Wuninitialized warning for.  In trying to fix this, I

discovered that GCC sometimes does not warn when it should.  Compile

the following program with 'gcc -O2 -Wall -S'.



   union YYSTYPE { int ival; };

   union YYSTYPE

   yyparse (void)

   {

     union YYSTYPE yylval;

     return yylval;

   }





   struct s { int ival; };

   struct s

   yyparse_with_struct (void)

   {

     struct s xxlval;

     return xxlval;

   }



Here's what I observe, for the above program:



$ gcc -O2 -Wall -S t.i

t.i: In function 'yyparse_with_struct':

t.i:15:6: warning: 'xxlval.ival' is used uninitialized in this function

[-Wuninitialized]



There should be a warning for yylval, but the warning is missing.

The (correct) warning for xxlval suggests that the problem has

to do with unions, not structs.

Reply via email to