diff --git a/src/reader.c b/src/reader.c index e776ed1f..32feb0dc 100644 --- a/src/reader.c +++ b/src/reader.c @@ -26,6 +26,7 @@ #include "complain.h" #include "conflicts.h" #include "files.h" +#include "fixits.h" #include "getargs.h" #include "gram.h" #include "muscle-tab.h" @@ -344,14 +345,22 @@ grammar_rule_check_and_complete (symbol_list *r) /* Check that %empty => empty rule. */ if (r->percent_empty_loc.start.file && r->next && r->next->content.sym) - complain (&r->percent_empty_loc, complaint, - _("%%empty on non-empty rule")); + { + complain (&r->percent_empty_loc, complaint, + _("%%empty on non-empty rule")); + fixits_register (&r->percent_empty_loc, ""); + } /* Check that empty rule => %empty. */ if (!(r->next && r->next->content.sym) && !r->midrule_parent_rule - && !r->percent_empty_loc.start.file) - complain (&r->location, Wempty_rule, _("empty rule without %%empty")); + && !r->percent_empty_loc.start.file + && warning_is_enabled (Wempty_rule)) + { + complain (&r->location, Wempty_rule, + _("empty rule without %%empty")); + fixits_register (&r->location, " %empty "); + } /* See comments in grammar_current_rule_prec_set for how POSIX mandates this complaint. It's only for identifiers, so skip diff --git a/tests/actions.at b/tests/actions.at index ec2e8836..7157805b 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -134,6 +134,7 @@ AT_BISON_CHECK([-fcaret -Wempty-rule 1.y], [0], [], [[1.y:11.17-18: warning: empty rule without %empty [-Wempty-rule] 11 | a: /* empty. */ {}; | ^~ +1.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]]) AT_DATA_GRAMMAR([[2.y]], @@ -151,6 +152,7 @@ AT_BISON_CHECK([-fcaret 2.y], [0], [], 2.y:13.17-18: warning: empty rule without %empty [-Wempty-rule] 13 | c: /* empty. */ {}; | ^~ +2.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]]) AT_BISON_CHECK([-fcaret -Wno-empty-rule 2.y], [0]) @@ -229,6 +231,7 @@ two.y:12.3-8: error: %empty on non-empty rule two.y:13.3-8: error: %empty on non-empty rule 13 | | %empty {} {} | ^~~~~~ +two.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]]) AT_BISON_OPTION_POPDEFS diff --git a/tests/diagnostics.at b/tests/diagnostics.at index ab5fde38..773982ff 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -112,6 +112,7 @@ input.y:16.2: warning: empty rule without %empty [-W input.y:17.3: warning: empty rule without %empty [-Wempty-rule] 17 | e: | ^ +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]]) @@ -158,6 +159,7 @@ input.y:17.4-17: warning: empty rule without %empty [warning: empty rule without %empty [-Wempty-rule] 18 | h: { 🐃 } | ^~~~~~~~~~~~~~ +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]]) @@ -180,6 +182,7 @@ b: {} 11 | a: {} | ^~ /dev/stdout:1.4-5: warning: empty rule without %empty [-Wempty-rule] +/dev/stdout: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]]) diff --git a/tests/existing.at b/tests/existing.at index 782633ad..018178bf 100644 --- a/tests/existing.at +++ b/tests/existing.at @@ -457,6 +457,7 @@ input.y:47.1-6: warning: useless associativity for UNARY, use %precedence [-Wpre input.y:50.1-5: warning: useless associativity for '$', use %precedence [-Wprecedence] input.y:51.1-5: warning: useless associativity for '(', use %precedence [-Wprecedence] input.y:51.1-5: warning: useless precedence and associativity for ')' [-Wprecedence] +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]], dnl LAST-STATE @@ -1428,6 +1429,7 @@ input.y:54.1-5: warning: useless associativity for HORELSE, use %precedence [-Wp input.y:55.1-5: warning: useless associativity for HANDTHEN, use %precedence [-Wprecedence] input.y:61.1-5: warning: useless associativity for HNOT, use %precedence [-Wprecedence] input.y:68.1-5: warning: useless associativity for UNEAR, use %precedence [-Wprecedence] +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]], dnl LAST-STATE @@ -2096,6 +2098,7 @@ input.y:157.1-5: warning: useless associativity for '`', use %precedence [-Wprec input.y:159.1-5: warning: useless associativity for '@<:@', use %precedence [-Wprecedence] input.y:170.1-5: warning: useless associativity for ',', use %precedence [-Wprecedence] input.y:181.1-6: warning: useless associativity for '!', use %precedence [-Wprecedence] +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] ]], dnl LAST-STATE