Skip to content

Commit 104ca74

Browse files
committed
doc: document -Wuseless-action
* doc/bison.texi, src/getargs.c, NEWS: here.
1 parent af92398 commit 104ca74

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
@@ -10471,6 +10471,41 @@ One would get the exact same parser with the following directives instead:
1047110471
@end group
1047210472
@end example
1047310473

10474+
@item useless-action
10475+
Useless explicit actions (@samp{@{ $$ = $1; @}}) are reported. For instance
10476+
on the following grammar:
10477+
10478+
@example
10479+
@group
10480+
$ @kbd{cat foo.y}
10481+
%type <int> "number" expr term
10482+
%%
10483+
expr: expr "+" term @{ $$ = $1 + $3; @}
10484+
| term @{ $$ = $1; @}
10485+
term: "(" expr ")" @{ $$ = $2; @}
10486+
| "number" @{ $$ = $1; @}
10487+
@end group
10488+
@end example
10489+
10490+
@noindent
10491+
@command{bison} diagnoses:
10492+
10493+
@example
10494+
$ @kbd{bison -Wuseless-action foo.y}
10495+
foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
10496+
| term @{ $$ = $1; @}
10497+
^~~~~~~~~~~~
10498+
foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
10499+
| "number" @{ $$ = $1; @}
10500+
^~~~~~~~~~~~
10501+
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
10502+
@end example
10503+
10504+
Running @kbd{bison -Wuseless-action --update foo.y} would remove these actions.
10505+
10506+
Actions with named references (e.g., @samp{@{ $expr = $term; @}}) are not
10507+
reported. To disable the warning locally, write @samp{@{ $$ = ($1); @}}.
10508+
1047410509
@item yacc
1047510510
Incompatibilities with POSIX Yacc.
1047610511

src/getargs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ Warning categories include:\n\
342342
'empty-rule' empty rules without %empty\n\
343343
'midrule-values' unset or unused midrule values\n\
344344
'precedence' useless precedence and associativity\n\
345+
'useless-action' useless explicit actions\n\
345346
'yacc' incompatibilities with POSIX Yacc\n\
346347
'other' all other warnings (enabled by default)\n\
347348
'all' all the warnings except 'yacc'\n\

0 commit comments

Comments
 (0)