File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,32 @@ GNU Bison NEWS
1818
1919** New features
2020
21+ *** New warning flag: -Wuseless-action
22+
23+ A new warning category is introduced: 'useless-action', which reports
24+ useless explicit actions. For instance on the following grammar:
25+
26+ %type <int> "number" expr term
27+ %%
28+ expr: expr "+" term { $$ = $1 + $3; }
29+ | term { $$ = $1; }
30+ term: "(" expr ")" { $$ = $2; }
31+ | "number" { $$ = $1; }
32+
33+ bison diagnoses:
34+
35+ $ bison -Wuseless-action foo.y
36+ foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
37+ 4 | | term { $$ = $1; }
38+ | ^~~~~~~~~~~~
39+ foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
40+ 6 | | "number" { $$ = $1; }
41+ | ^~~~~~~~~~~~
42+ foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
43+
44+ Running 'bison -Wuseless-action --update foo.y' would remove these
45+ actions.
46+
2147*** Lookahead correction in C++
2248
2349 Contributed by Adrian Vogelsgesang.
Original file line number Diff line number Diff line change @@ -10635,6 +10635,41 @@ One would get the exact same parser with the following directives instead:
1063510635@end group
1063610636@end example
1063710637
10638+ @item useless-action
10639+ Useless explicit actions (@samp {@{ $$ = $1; @} }) are reported. For instance
10640+ on the following grammar:
10641+
10642+ @example
10643+ @group
10644+ $ @kbd {cat foo.y }
10645+ %type <int> "number" expr term
10646+ %%
10647+ expr: expr "+" term @{ $$ = $1 + $3; @}
10648+ | term @{ $$ = $1; @}
10649+ term: "(" expr ")" @{ $$ = $2; @}
10650+ | "number" @{ $$ = $1; @}
10651+ @end group
10652+ @end example
10653+
10654+ @noindent
10655+ @command {bison } diagnoses:
10656+
10657+ @example
10658+ $ @kbd {bison -Wuseless-action foo.y }
10659+ foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
10660+ | term @{ $$ = $1; @}
10661+ ^~~~~~~~~~~~
10662+ foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
10663+ | "number" @{ $$ = $1; @}
10664+ ^~~~~~~~~~~~
10665+ foo.y: warning: fix-its can be applied. Rerun with option '-- update'. [-Wother]
10666+ @end example
10667+
10668+ Running @kbd {bison -Wuseless-action --update foo.y } would remove these actions.
10669+
10670+ Actions with named references (e.g., @samp {@{ $expr = $term; @} }) are not
10671+ reported. To disable the warning locally, write @samp {@{ $$ = ($1); @} }.
10672+
1063810673@item yacc
1063910674Incompatibilities with POSIX Yacc.
1064010675
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ static const argmatch_warning_arg argmatch_warning_args[] =
137137 { "deprecated" , Wdeprecated },
138138 { "empty-rule" , Wempty_rule },
139139 { "precedence" , Wprecedence },
140+ { "useless-action" , Wuseless_action },
140141 { "other" , Wother },
141142 { "all" , Wall },
142143 { "everything" , Weverything },
You can’t perform that action at this time.
0 commit comments