Skip to content

Commit 0b3773f

Browse files
committed
doc: document -Wuseless-action
* doc/bison.texi, src/getargs.c, NEWS: here.
1 parent 6d2d99f commit 0b3773f

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

NEWS

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,37 @@ GNU Bison NEWS
88

99
** New features
1010

11+
*** Java: disabled debug code
12+
1113
The Java backend no longer emits code and data for parser tracing if the
1214
%define variable parse.trace is not defined.
1315

16+
*** New warning flag: -Wuseless-action
17+
18+
A new warning category is introduced: 'useless-action', which reports
19+
useless explicit actions. For instance on the following grammar:
20+
21+
%type <int> "number" expr term
22+
%%
23+
expr: expr "+" term { $$ = $1 + $3; }
24+
| term { $$ = $1; }
25+
term: "(" expr ")" { $$ = $2; }
26+
| "number" { $$ = $1; }
27+
28+
bison diagnoses:
29+
30+
$ bison -Wuseless-action foo.y
31+
foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
32+
4 | | term { $$ = $1; }
33+
| ^~~~~~~~~~~~
34+
foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
35+
6 | | "number" { $$ = $1; }
36+
| ^~~~~~~~~~~~
37+
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
38+
39+
Running 'bison -Wuseless-action --update foo.y' would remove these
40+
actions.
41+
1442
* Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
1543

1644
** Bug fixes

doc/bison.texi

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10598,6 +10598,41 @@ One would get the exact same parser with the following directives instead:
1059810598
@end group
1059910599
@end example
1060010600

10601+
@item useless-action
10602+
Useless explicit actions (@samp{@{ $$ = $1; @}}) are reported. For instance
10603+
on the following grammar:
10604+
10605+
@example
10606+
@group
10607+
$ @kbd{cat foo.y}
10608+
%type <int> "number" expr term
10609+
%%
10610+
expr: expr "+" term @{ $$ = $1 + $3; @}
10611+
| term @{ $$ = $1; @}
10612+
term: "(" expr ")" @{ $$ = $2; @}
10613+
| "number" @{ $$ = $1; @}
10614+
@end group
10615+
@end example
10616+
10617+
@noindent
10618+
@command{bison} diagnoses:
10619+
10620+
@example
10621+
$ @kbd{bison -Wuseless-action foo.y}
10622+
foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
10623+
| term @{ $$ = $1; @}
10624+
^~~~~~~~~~~~
10625+
foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
10626+
| "number" @{ $$ = $1; @}
10627+
^~~~~~~~~~~~
10628+
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
10629+
@end example
10630+
10631+
Running @kbd{bison -Wuseless-action --update foo.y} would remove these actions.
10632+
10633+
Actions with named references (e.g., @samp{@{ $expr = $term; @}}) are not
10634+
reported. To disable the warning locally, write @samp{@{ $$ = ($1); @}}.
10635+
1060110636
@item yacc
1060210637
Incompatibilities with POSIX Yacc.
1060310638

src/complain.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static const argmatch_warning_arg argmatch_warning_args[] =
139139
{ "deprecated", Wdeprecated },
140140
{ "empty-rule", Wempty_rule },
141141
{ "precedence", Wprecedence },
142+
{ "useless-action", Wuseless_action },
142143
{ "other", Wother },
143144
{ "all", Wall },
144145
{ "everything", Weverything },

0 commit comments

Comments
 (0)