help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pure-parser warning: ‘yylval’ is used uninitialized in this function


From: Joel E. Denny
Subject: Re: pure-parser warning: ‘yylval’ is used uninitialized in this function
Date: Sat, 10 May 2008 19:43:29 -0400 (EDT)

On Thu, 8 May 2008, Kaiwang Chen wrote:

> GCC with "-Os -Wall -Werror" complains in the case of pure-parser, while
> without -Os it works well. Any help? Thanks in advance.
> 
> $ bison -o parse.c parse.y
> $ gcc -Os -Wall -Werror  -c parse.c -o parse.o
> cc1: warnings being treated as errors
> parse.c: In function ???yyparse???:
> parse.c:1247: warning: ???yylval??? is used uninitialized in this function

According to the gcc documentation, -Wuninitialized (implied by -Wall) is 
affected by the optimization level.

> static int yylex(YYSTYPE *lvalp)
> {
>     return YYEOF;
> }

The warning seems legitimate to me because you're not setting *lvalp in 
yylex.

If yylex is not declared static, the warning goes away.  I'm thinking that 
gcc believes yylex is capable of initializing yylval, but gcc gives up 
when it sees that yylex could have external linking.

When I keep yylex static and initialize *lvalp within it, the warning line 
number moves to 1035, which is the declaration of yylval.  I don't 
understand what that means.  I would've guessed the warning should always 
have the line number of a usage of yylval.  Maybe gcc has a bug.

I don't have time to pursue this further right now.  Maybe someone can 
take this to the gcc maintainers for advice.  If you find an answer, 
please let us know.

As a workaround, you can add this to your definitions section:

  %initial-action { $$ = 0; }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]