This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/54804] New: -Wuninitialized fails to warn about uninitialized local union
- From: "eggert at gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 04 Oct 2012 00:27:53 +0000
- Subject: [Bug c/54804] New: -Wuninitialized fails to warn about uninitialized local union
- Auto-submitted: auto-generated
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.