bug-bison
[Top][All Lists]
Advanced

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

Re: Adding %destructor surprisingly enables warnings


From: Akim Demaille
Subject: Re: Adding %destructor surprisingly enables warnings
Date: Fri, 16 Nov 2018 17:52:19 +0100

Hi!

> Le 16 nov. 2018 à 12:23, Askar Safin <address@hidden> a écrit :
> 
> Hi. I noticed strange behavior in Bison. Probably I simply don't understand 
> something. Or I found a bug.
> This is my input file: http://paste.debian.net/hidden/a72e301e . I process it 
> using the following command line: "bison -do test.tab.cpp test.ypp".
> Bison shows no warnings.
> Then I add one line. This is edited file: 
> http://paste.debian.net/hidden/1d8be22a .

The diff is:

address@hidden ~bison $ diff ~/Downloads/paste_a72e301e.txt 
~/Downloads/paste_1d8be22a.txt
--- /Users/akim/Downloads/paste_a72e301e.txt    2018-11-16 17:43:21.296705198 
+0100
+++ /Users/akim/Downloads/paste_1d8be22a.txt    2018-11-16 17:43:10.564650439 
+0100
@@ -53,6 +53,8 @@
 
 %start document
 
+%destructor { delete $$; } <val *>
+
 %%
 
 %type <val *> expr;


> And then I process it using the same command line.
> And I see the following warnings:
> 
> test.ypp:63.3-66.5: warning: unset value: $$ [-Wother]
>   ID[id]
>   ^^^^^^
> test.ypp:71.3-73.5: warning: unset value: $$ [-Wother]
> | '\'' expr[e]
>   ^^^^^^^^^^^^
> test.ypp:71.8-11: warning: unused value: $2 [-Wother]
> | '\'' expr[e]
>        ^^^^
> test.ypp:78.3-80.5: warning: unset value: $$ [-Wother]
>   %empty
>   ^^^^^^
> test.ypp:81.3-83.5: warning: unset value: $$ [-Wother]
> | expr[car] exprs[cdr]
>   ^^^^^^^^^^^^^^^^^^^^
> test.ypp:81.3-6: warning: unused value: $1 [-Wother]
> | expr[car] exprs[cdr]
>   ^^^^
> test.ypp:81.13-17: warning: unused value: $2 [-Wother]
> | expr[car] exprs[cdr]
>             ^^^^^

Well, your file is very fishy.  Bison is complaining about this:

expr:
  ID[id]
    {
      std::move (*$id);
    }

you are telling it that expr has a value, yet you don’t set it.  You must write

expr:
  ID[id]
    {
      $$ = SOMETHING(std::move (*$id));
    }

The documentation is indeed lacking details on this regard.  The code is 
clearer :)

/*----------------------------------------------------------------------.
| A symbol should be used if either:                                    |
|   1. It has a destructor.                                             |
|   2. The symbol is a midrule symbol (i.e., the generated LHS          |
|      replacing a midrule action) that was assigned to or used, as in  |
|      "exp: { $$ = 1; } { $$ = $1; }".                                 |
`----------------------------------------------------------------------*/


> My OS is Debian Stretch x86_64. Bison installed from Debian repo. "dpkg -l 
> bison" reports "2:3.0.4.dfsg-1+b1". "bison --version" reports "3.0.4".
> 
> So, it seems that Bison for unknown reason ignores « %define parse.error 
> verbose", but %destructor somehow causes Bison to actually show warnings.

I think you misunderstand parse.error: its point is to make *your* parser more 
verbose, not the one of Bison.  Bison’s warnings are tuned with -W.

Cheers.


reply via email to

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