[Bug c/54804] New: -Wuninitialized fails to warn about uninitialized local union

eggert at gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Oct 4 00:28:00 GMT 2012


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: unassigned@gcc.gnu.org
        ReportedBy: eggert@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.



More information about the Gcc-bugs mailing list