summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2019-09-06 17:47:16 +0200
committerAkim Demaille <akim.demaille@gmail.com>2019-09-07 17:09:43 +0200
commit378963b1396272a1707e2f888dea7e2376a0e8ae (patch)
tree4531c42e8190812d79f0284275480668bab90afa
parent2dd882bce5a37996cbcaa9a646cde7221d30ad7d (diff)
downloadbison-378963b1396272a1707e2f888dea7e2376a0e8ae.tar.gz
tests: check token redeclaration
* src/symtab.c (symbol_class_set): Report previous definitions when redeclared. * tests/input.at (Symbol redeclared): New.
-rw-r--r--src/symtab.c8
-rw-r--r--tests/diagnostics.at15
-rw-r--r--tests/input.at32
-rw-r--r--tests/regression.at9
4 files changed, 58 insertions, 6 deletions
diff --git a/src/symtab.c b/src/symtab.c
index 60733e72..684fdf3d 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -462,7 +462,13 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
if (declaring)
{
if (s->status == declared)
- complain (&loc, Wother, _("symbol %s redeclared"), sym->tag);
+ {
+ unsigned i = 0;
+ complain (&loc, Wother, _("symbol %s redeclared"), sym->tag);
+ i += SUB_INDENT;
+ complain_indent (&sym->location, Wother, &i,
+ _("previous declaration"));
+ }
else
s->status = declared;
}
diff --git a/tests/diagnostics.at b/tests/diagnostics.at
index 3f9e19fa..15815db3 100644
--- a/tests/diagnostics.at
+++ b/tests/diagnostics.at
@@ -67,18 +67,33 @@ exp: %empty;
[[input.y:9.12-14: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
9 | %token FOO <warning>FOO</warning> FOO
| <warning>^~~</warning>
+input.y:9.8-10: previous declaration
+ 9 | %token <note>FOO</note> FOO FOO
+ | <note>^~~</note>
input.y:9.16-18: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
9 | %token FOO FOO <warning>FOO</warning>
| <warning>^~~</warning>
+input.y:9.8-10: previous declaration
+ 9 | %token <note>FOO</note> FOO FOO
+ | <note>^~~</note>
input.y:10.8-10: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
10 | %token <warning>FOO</warning> FOO FOO
| <warning>^~~</warning>
+input.y:9.8-10: previous declaration
+ 9 | %token <note>FOO</note> FOO FOO
+ | <note>^~~</note>
input.y:10.13-15: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
10 | %token FOO <warning>FOO</warning> FOO
| <warning>^~~</warning>
+input.y:9.8-10: previous declaration
+ 9 | %token <note>FOO</note> FOO FOO
+ | <note>^~~</note>
input.y:10.18-20: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
10 | %token FOO FOO <warning>FOO</warning>
| <warning>^~~</warning>
+input.y:9.8-10: previous declaration
+ 9 | %token <note>FOO</note> FOO FOO
+ | <note>^~~</note>
]])
diff --git a/tests/input.at b/tests/input.at
index 2cc829f5..660cacc9 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -615,6 +615,38 @@ AT_CHECK_UNUSED_VALUES([1], [1])
AT_CLEANUP
+## ------------------- ##
+## Symbol redeclared. ##
+## ------------------- ##
+
+AT_SETUP([Symbol redeclared])
+
+AT_DATA([[input.y]],
+[[%token FOO FOO
+%token BAR 12 BAR 12
+
+%%
+exp: FOO BAR
+]])
+
+AT_BISON_CHECK([-fcaret input.y], [0], [],
+[[input.y:1.12-14: warning: symbol FOO redeclared [-Wother]
+ 1 | %token FOO FOO
+ | ^~~
+input.y:1.8-10: previous declaration
+ 1 | %token FOO FOO
+ | ^~~
+input.y:2.15-17: warning: symbol BAR redeclared [-Wother]
+ 2 | %token BAR 12 BAR 12
+ | ^~~
+input.y:2.8-10: previous declaration
+ 2 | %token BAR 12 BAR 12
+ | ^~~
+]])
+
+AT_CLEANUP
+
+
## --------------------------- ##
## Symbol class redefinition. ##
## --------------------------- ##
diff --git a/tests/regression.at b/tests/regression.at
index 507bcbb4..55a3c95b 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -397,19 +397,18 @@ AT_BISON_OPTION_POPDEFS
# unnecessarily escaped here even though it would need to be if encoded in a
# C-string literal. Also notice that unnecessary escaping, such as "\?", from
# the user specification is eliminated.
-AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
-[[input.y:22.8-14: warning: symbol SPECIAL redeclared [-Wother]
-input.y:22.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
-]])
-
AT_BISON_CHECK([-fcaret -o input.c input.y], [[0]], [[]],
[[input.y:22.8-14: warning: symbol SPECIAL redeclared [-Wother]
22 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
| ^~~~~~~
+input.y:21.8-14: previous declaration
+ 21 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
+ | ^~~~~~~
input.y:22.16-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string [-Wother]
22 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
]])
+
AT_COMPILE([input])
# Checking the error message here guarantees that yytname, which does contain