Skip to content

Commit 5a47e23

Browse files
committed
doc: document -Wuseless-action
* doc/bison.texi, src/getargs.c, NEWS: here.
1 parent 844824a commit 5a47e23

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

NEWS

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@ GNU Bison NEWS
22

33
* Noteworthy changes in release ?.? (????-??-??) [?]
44

5+
*** Diagnostics for stylistic issues: -Wuseless-action
6+
7+
A new warning category is introduced: 'style'. Currently it reports
8+
useless explicit actions. For instance on the following grammar:
9+
10+
%type <int> "number" expr term
11+
%%
12+
expr: expr "+" term { $$ = $1 + $3; }
13+
| term { $$ = $1; }
14+
term: "(" expr ")" { $$ = $2; }
15+
| "number" { $$ = $1; }
16+
17+
bison diagnoses:
18+
19+
$ bison -Wuseless-action foo.y
20+
foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
21+
| term { $$ = $1; }
22+
^~~~~~~~~~~~
23+
foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
24+
| "number" { $$ = $1; }
25+
^~~~~~~~~~~~
26+
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
27+
28+
Running 'bison -Wuseless-action --update foo.y' would remove these actions.
529

630
* Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
731

doc/bison.texi

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

10493+
@item useless-action
10494+
Useless explicit actions (@samp{@{ $$ = $1; @}}) are reported. For instance
10495+
on the following grammar:
10496+
10497+
@example
10498+
@group
10499+
$ @kbd{cat foo.y}
10500+
%type <int> "number" expr term
10501+
%%
10502+
expr: expr "+" term @{ $$ = $1 + $3; @}
10503+
| term @{ $$ = $1; @}
10504+
term: "(" expr ")" @{ $$ = $2; @}
10505+
| "number" @{ $$ = $1; @}
10506+
@end group
10507+
@end example
10508+
10509+
@noindent
10510+
@command{bison} diagnoses:
10511+
10512+
@example
10513+
$ @kbd{bison -Wuseless-action foo.y}
10514+
foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
10515+
| term @{ $$ = $1; @}
10516+
^~~~~~~~~~~~
10517+
foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
10518+
| "number" @{ $$ = $1; @}
10519+
^~~~~~~~~~~~
10520+
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
10521+
@end example
10522+
10523+
Running @kbd{bison -Wuseless-action --update foo.y} would remove these actions.
10524+
10525+
Actions with named references (e.g., @samp{@{ $expr = $term; @}}) are not
10526+
reported. To disable the warning locally, write @samp{@{ $$ = ($1); @}}.
10527+
1049310528
@item yacc
1049410529
Incompatibilities with POSIX Yacc.
1049510530

src/getargs.c

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

0 commit comments

Comments
 (0)