Skip to content

Commit

Permalink
doc: document -Wuseless-action
Browse files Browse the repository at this point in the history
* doc/bison.texi, src/getargs.c, NEWS: here.
  • Loading branch information
akimd committed Jul 26, 2019
1 parent 6d2d99f commit 0b3773f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
28 changes: 28 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,37 @@ GNU Bison NEWS

** New features

*** Java: disabled debug code

The Java backend no longer emits code and data for parser tracing if the
%define variable parse.trace is not defined.

*** New warning flag: -Wuseless-action

A new warning category is introduced: 'useless-action', which reports
useless explicit actions. For instance on the following grammar:

%type <int> "number" expr term
%%
expr: expr "+" term { $$ = $1 + $3; }
| term { $$ = $1; }
term: "(" expr ")" { $$ = $2; }
| "number" { $$ = $1; }

bison diagnoses:

$ bison -Wuseless-action foo.y
foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
4 | | term { $$ = $1; }
| ^~~~~~~~~~~~
foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
6 | | "number" { $$ = $1; }
| ^~~~~~~~~~~~
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]

Running 'bison -Wuseless-action --update foo.y' would remove these
actions.

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

** Bug fixes
Expand Down
35 changes: 35 additions & 0 deletions doc/bison.texi
Original file line number Diff line number Diff line change
Expand Up @@ -10598,6 +10598,41 @@ One would get the exact same parser with the following directives instead:
@end group
@end example

@item useless-action
Useless explicit actions (@samp{@{ $$ = $1; @}}) are reported. For instance
on the following grammar:

@example
@group
$ @kbd{cat foo.y}
%type <int> "number" expr term
%%
expr: expr "+" term @{ $$ = $1 + $3; @}
| term @{ $$ = $1; @}
term: "(" expr ")" @{ $$ = $2; @}
| "number" @{ $$ = $1; @}
@end group
@end example

@noindent
@command{bison} diagnoses:

@example
$ @kbd{bison -Wuseless-action foo.y}
foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
| term @{ $$ = $1; @}
^~~~~~~~~~~~
foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
| "number" @{ $$ = $1; @}
^~~~~~~~~~~~
foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
@end example

Running @kbd{bison -Wuseless-action --update foo.y} would remove these actions.

Actions with named references (e.g., @samp{@{ $expr = $term; @}}) are not
reported. To disable the warning locally, write @samp{@{ $$ = ($1); @}}.

@item yacc
Incompatibilities with POSIX Yacc.

Expand Down
1 change: 1 addition & 0 deletions src/complain.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static const argmatch_warning_arg argmatch_warning_args[] =
{ "deprecated", Wdeprecated },
{ "empty-rule", Wempty_rule },
{ "precedence", Wprecedence },
{ "useless-action", Wuseless_action },
{ "other", Wother },
{ "all", Wall },
{ "everything", Weverything },
Expand Down

0 comments on commit 0b3773f

Please sign in to comment.