On 09/19/2012 06:05 AM, Akim Demaille wrote:
> I have not seen answers to this message.

Sorry, I missed that one.  Thanks for the example;
I think I see the problem now.  This appears to be
a bug in GCC -- has someone filed a bug report?

Anyway, we can't expect users to get a fixed GCC, so it'd
be nice to pacify the buggy one.  But
instead of initializing yylval to zero, which
is troublesome, how about if we initialize it
to the value of the first input symbol?

That is, instead of this:

  yychar = YYEMPTY; /* Cause a token to be read.  */

How about if we do something like this:

  yychar = YYEMPTY;
#ifdef __GNUC__
  /* Avoid diagnostic "'yylval' may be used uninitialized in this               
     function".  Without this extra help, 'gcc -Wmaybe-uninitialized'           
     is not smart enough to see that yylval is always OK.  */
  if (YYFINAL != 0 && !yypact_value_is_default (yypact[0]))
    yychar = YYLEX;
#endif

That way, GCC will be happy in the usual case.  It will optimize
away most of the above gorp, and generate code that simply does
"yychar = YYLEX".  And in the unusual case where
where yylval really *isn't* initialized -- because the lexer is
buggy -- GCC will issue the warning, which will be a good thing.

Reply via email to