mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 06:13:02 +00:00
diagnostics: complain about undeclared string tokens
String literals, which allow for better error messages, are (too)
liberally accepted by Bison, which might result in silent errors. For
instance
%type <exVal> cond "condition"
does not define “condition” as a string alias to 'cond' (nonterminal
symbols do not have string aliases). It is rather equivalent to
%nterm <exVal> cond
%token <exVal> "condition"
i.e., it gives the type 'exVal' to the "condition" token, which was
clearly not the intention.
Introduce -Wdangling-alias to catch this.
* src/complain.h, src/complain.c: Add support for -Wdangling-alias.
(argmatch_warning_args): Sort.
* src/symtab.c (symbol_check_defined): Complain about dangling
aliases.
* doc/bison.texi: Document it.
* tests/input.at (Dangling aliases): New test.
This commit is contained in:
@@ -26,12 +26,12 @@
|
||||
#include <assure.h>
|
||||
#include <fstrcmp.h>
|
||||
#include <hash.h>
|
||||
#include <quote.h>
|
||||
|
||||
#include "complain.h"
|
||||
#include "getargs.h"
|
||||
#include "gram.h"
|
||||
#include "intprops.h"
|
||||
#include "quote.h"
|
||||
|
||||
static struct hash_table *symbol_table = NULL;
|
||||
static struct hash_table *semantic_type_table = NULL;
|
||||
@@ -610,6 +610,13 @@ symbol_check_defined (symbol *sym)
|
||||
s->number = nvars++;
|
||||
}
|
||||
|
||||
if (s->class == token_sym
|
||||
&& sym->tag[0] == '"'
|
||||
&& !sym->is_alias)
|
||||
complain (&sym->location, Wdangling_alias,
|
||||
_("string literal %s not attached to a symbol"),
|
||||
sym->tag);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
symbol_code_props_get (sym, i)->is_used = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user