On 09/28/2012 12:22 AM, Akim Demaille wrote: > That's not true: the test case I sent _does_ use that > initial yylval, yet GCC does not complain.
Ouch. I looked into that, and it's a GCC bug. I filed a bug report here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54804 In the meantime, here is a similar grammar that does not run afoul of the GCC bug, i.e., GCC correctly reports that yylval is uninitialized: %pure-parser %code { #define YYSTYPE double extern void report_error (const char *); extern void handle_value (int); static void yyerror (const char *msg) { report_error (msg); } static int yylex (YYSTYPE *lvalp) { static const char *input = "a"; return *input++; } int main (void) { return yyparse (); } } %token 'a'; %% exp: 'a' { handle_value ($1); }; Compile it this way, with Bison master: bison bar.y gcc -S -Wall -O2 bar.tab.c I get the correct warning: bar.tab.c: In function 'yyparse': bar.tab.c:1133:12: warning: 'yylval' may be used uninitialized in this function [-Wuninitialized] If we alter Bison to always initialize yylval, we'll suppress this correct warning. On the other hand, if we use the patch I'm proposing, the warning should still be generated.
