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 @@ -85,6 +85,32 @@ GNU Bison NEWS
8585
8686** New features
8787
88+ *** New warning flag: -Wuseless-action
89+
90+ A new warning category is introduced: 'useless-action', which reports
91+ useless explicit actions. For instance on the following grammar:
92+
93+ %type <int> "number" expr term
94+ %%
95+ expr: expr "+" term { $$ = $1 + $3; }
96+ | term { $$ = $1; }
97+ term: "(" expr ")" { $$ = $2; }
98+ | "number" { $$ = $1; }
99+
100+ bison diagnoses:
101+
102+ $ bison -Wuseless-action foo.y
103+ foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
104+ 4 | | term { $$ = $1; }
105+ | ^~~~~~~~~~~~
106+ foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
107+ 6 | | "number" { $$ = $1; }
108+ | ^~~~~~~~~~~~
109+ foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
110+
111+ Running 'bison -Wuseless-action --update foo.y' would remove these
112+ actions.
113+
88114*** Lookahead correction in C++
89115
90116 Contributed by Adrian Vogelsgesang.
Original file line number Diff line number Diff line change @@ -10682,6 +10682,41 @@ One would get the exact same parser with the following directives instead:
1068210682@end group
1068310683@end example
1068410684
10685+ @item useless-action
10686+ Useless explicit actions (@samp{@{ $$ = $1; @}}) are reported. For instance
10687+ on the following grammar:
10688+
10689+ @example
10690+ @group
10691+ $ @kbd{cat foo.y}
10692+ %type <int> "number" expr term
10693+ %%
10694+ expr: expr "+" term @{ $$ = $1 + $3; @}
10695+ | term @{ $$ = $1; @}
10696+ term: "(" expr ")" @{ $$ = $2; @}
10697+ | "number" @{ $$ = $1; @}
10698+ @end group
10699+ @end example
10700+
10701+ @noindent
10702+ @command{bison} diagnoses:
10703+
10704+ @example
10705+ $ @kbd{bison -Wuseless-action foo.y}
10706+ foo.y:4.21-32: warning: useless explicit action [-Wuseless-action]
10707+ | term @{ $$ = $1; @}
10708+ ^~~~~~~~~~~~
10709+ foo.y:6.21-32: warning: useless explicit action [-Wuseless-action]
10710+ | "number" @{ $$ = $1; @}
10711+ ^~~~~~~~~~~~
10712+ foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
10713+ @end example
10714+
10715+ Running @kbd{bison -Wuseless-action --update foo.y} would remove these actions.
10716+
10717+ Actions with named references (e.g., @samp{@{ $expr = $term; @}}) are not
10718+ reported. To disable the warning locally, write @samp{@{ $$ = ($1); @}}.
10719+
1068510720@item yacc
1068610721Incompatibilities with POSIX Yacc.
1068710722
Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ static const argmatch_warning_arg argmatch_warning_args[] =
141141 { "none" , Wnone },
142142 { "other" , Wother },
143143 { "precedence" , Wprecedence },
144+ { "useless-action" , Wuseless_action },
144145 { "yacc" , Wyacc },
145146 { NULL , Wnone }
146147};
You can’t perform that action at this time.
0 commit comments