help-bison
[Top][All Lists]
Advanced

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

Re: %destructor and unused values


From: Akim Demaille
Subject: Re: %destructor and unused values
Date: Mon, 28 Jan 2013 13:35:50 +0100

Hi John,
Le 28 janv. 2013 à 12:41, John P. Hartmann <address@hidden> a écrit :

> I have a fine grammar, but I get unset value warnings in droves when I add
> empty %destructor declartions (the error token is not [yet] referenced).
> 
> This applies to Bison 2.5 on Fedora 17 and also 2.4.1 on Fedora13.
> 
> %union
> {
>   struct instruction * inst;
>   struct expression * exp;
>   struct term term;
>   int kwd;
> }
> 
> /*
> %destructor {} <inst>
> %destructor {} <exp>
> %destructor {} <term>
> */
> %destructor {} <kwd>
> 
> The offending rule:
> 
>               |  PARSE parsehow parsecase parsewhat SEMICOLON
>                  {
>                     $$=GETINSTXP(@$, parse, $4);
>                  }
> 
> The messages:
> 
> rexxy.y:401.19-404.19: warning: unused value: $2
> rexxy.y:401.19-404.19: warning: unused value: $3
> 
> It is true that $2 and $3 are not referenced in the action.  In this
> particular context they are valid, but have no effect.
> 
> If I comment out the destructor, the grammar is processed without errors or
> warnings.

If you declared destructors for parsehow and parsecase,
it is understood as "these symbols allocated memory
that needs to be reclaimed before the symbol is destroyed".

Bison can "see" that you are not using these symbols
in the action, so you are certainly leaking them.  The
parser will _not_ reclaim them: %destructor is there
for error recovery, not to reclaim the memory
of rhs symbols in an action reduction.


reply via email to

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