File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed
Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,34 @@ GNU Bison NEWS
22
33* Noteworthy changes in release ?.? (????-??-??) [?]
44
5+ ** New features
6+
7+ *** New warning flag: -Wuseless-action
8+
9+ A new warning category is introduced: 'useless-action', which reports
10+ useless explicit actions. For instance on the following grammar:
11+
12+ %type <int> "number" expr term
13+ %%
14+ expr: expr "+" term { $$ = $1 + $3; }
15+ | term { $$ = $1; }
16+ term: "(" expr ")" { $$ = $2; }
17+ | "number" { $$ = $1; }
18+
19+ bison diagnoses:
20+
21+ $ bison -Wuseless-action foo.y
22+ foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
23+ 4 | | term { $$ = $1; }
24+ | ^~~~~~~~~~~~
25+ foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
26+ 6 | | "number" { $$ = $1; }
27+ | ^~~~~~~~~~~~
28+ foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
29+
30+ Running 'bison -Wuseless-action --update foo.y' would remove these
31+ actions.
32+
533
634* Noteworthy changes in release 3.6.90 (2020-07-04) [beta]
735
Original file line number Diff line number Diff line change @@ -11360,6 +11360,41 @@ One would get the exact same parser with the following directives instead:
1136011360@end group
1136111361@end example
1136211362
11363+ @item useless-action
11364+ Useless explicit actions (@samp{@{ $$ = $1; @}}) are reported. For instance
11365+ on the following grammar:
11366+
11367+ @example
11368+ @group
11369+ $ @kbd{cat foo.y}
11370+ %type <int> "number" expr term
11371+ %%
11372+ expr: expr "+" term @{ $$ = $1 + $3; @}
11373+ | term @{ $$ = $1; @}
11374+ term: "(" expr ")" @{ $$ = $2; @}
11375+ | "number" @{ $$ = $1; @}
11376+ @end group
11377+ @end example
11378+
11379+ @noindent
11380+ @command{bison} diagnoses:
11381+
11382+ @example
11383+ $ @kbd{bison -Wuseless-action foo.y}
11384+ foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
11385+ | term @{ $$ = $1; @}
11386+ ^~~~~~~~~~~~
11387+ foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
11388+ | "number" @{ $$ = $1; @}
11389+ ^~~~~~~~~~~~
11390+ foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
11391+ @end example
11392+
11393+ Running @kbd{bison -Wuseless-action --update foo.y} would remove these actions.
11394+
11395+ Actions with named references (e.g., @samp{@{ $expr = $term; @}}) are not
11396+ reported. To disable the warning locally, write @samp{@{ $$ = ($1); @}}.
11397+
1136311398@item yacc
1136411399Incompatibilities with POSIX Yacc.
1136511400
Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ static const argmatch_warning_arg argmatch_warning_args[] =
161161 { "none" , Wnone },
162162 { "other" , Wother },
163163 { "precedence" , Wprecedence },
164+ { "useless-action" , Wuseless_action },
164165 { "yacc" , Wyacc },
165166 { NULL , Wnone }
166167};
You can’t perform that action at this time.
0 commit comments