diagnostics: don't crash when declaring the error token as an nterm

Reported by wcventure.
http://lists.gnu.org/archive/html/bug-bison/2019-03/msg00008.html

* src/symtab.c (complain_class_redeclared): Don't print empty
locations.
There can only be empty locations for predefined symbols.  And the
only symbol that is lexically available is the error token.  So this
appears to be the only possible way to have an error involving an
empty location.
* tests/input.at (Symbol class redefinition): Check it.
This commit is contained in:
Akim Demaille
2019-03-30 09:37:22 +01:00
parent bbf37f2534
commit a8558bc5a6
2 changed files with 11 additions and 4 deletions

View File

@@ -309,9 +309,12 @@ complain_class_redeclared (symbol *sym, symbol_class class, location second)
class == token_sym class == token_sym
? _("symbol %s redeclared as a token") ? _("symbol %s redeclared as a token")
: _("symbol %s redeclared as a nonterminal"), sym->tag); : _("symbol %s redeclared as a nonterminal"), sym->tag);
i += SUB_INDENT; if (!location_empty (sym->location))
complain_indent (&sym->location, complaint, &i, {
_("previous definition")); i += SUB_INDENT;
complain_indent (&sym->location, complaint, &i,
_("previous definition"));
}
} }

View File

@@ -625,6 +625,7 @@ AT_DATA([[input.y]],
[[%token FOO [[%token FOO
%nterm FOO BAR %nterm FOO BAR
%token BAR %token BAR
%nterm error // The token error cannot be redefined as an nterm.
%% %%
FOO: BAR FOO: BAR
BAR: BAR:
@@ -643,7 +644,10 @@ input.y:3.8-10: error: symbol BAR redeclared as a token
input.y:2.12-14: previous definition input.y:2.12-14: previous definition
%nterm FOO BAR %nterm FOO BAR
^~~ ^~~
input.y:5.1-3: error: rule given for FOO, which is a token input.y:4.8-12: error: symbol error redeclared as a nonterminal
%nterm error // The token error cannot be redefined as an nterm.
^~~~~
input.y:6.1-3: error: rule given for FOO, which is a token
FOO: BAR FOO: BAR
^~~ ^~~
]]) ]])