mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 05:43:03 +00:00
Don't miss %merge result type warnings just because the LHS types are
declared after the %merge. * src/reader.c (get_merge_function): Don't set the merger type yet. (record_merge_function_type): New function for setting the merger type and checking for clashes. (grammar_current_rule_merge_set): Set the location of the %merge for the current rule. (packgram): Invoke record_merge_function_type for each rule now that all symbol type declarations have been parsed. * src/reader.h (merger_list.type_declaration_location): New member storing the location of the first %merge from which the type for this merging function was derived. * src/symlist.h (symbol_list.merger_declaration_location): New member storing the location of a rule's %merge, if any. * tests/glr-regression.at (Missed %merge type warnings when LHS type is declared later): New test to catch the error fixed by the above patch.
This commit is contained in:
@@ -1661,3 +1661,58 @@ AT_CHECK([[./glr-regr17]], 0, [],
|
||||
])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## -------------------------------------------------------------##
|
||||
## Missed %merge type warnings when LHS type is declared later. ##
|
||||
## -------------------------------------------------------------##
|
||||
|
||||
AT_SETUP([Missed %merge type warnings when LHS type is declared later])
|
||||
AT_DATA_GRAMMAR([glr-regr18.y],
|
||||
[[%glr-parser
|
||||
|
||||
%{
|
||||
static void yyerror (char const *);
|
||||
static int yylex ();
|
||||
%}
|
||||
|
||||
%union {
|
||||
int type1;
|
||||
int type2;
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
sym1: sym2 %merge<merge> { $$ = $1; } ;
|
||||
sym2: %merge<merge> { $$ = 0; } ;
|
||||
|
||||
%type <type1> sym1;
|
||||
%type <type2> sym2;
|
||||
|
||||
%%
|
||||
|
||||
static void
|
||||
yyerror (char const *msg)
|
||||
{
|
||||
fprintf (stderr, "%s\n", msg);
|
||||
}
|
||||
|
||||
static int
|
||||
yylex ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
return yyparse ();
|
||||
}
|
||||
]])
|
||||
|
||||
AT_CHECK([[bison -o glr-regr18.c glr-regr18.y]], 0, [],
|
||||
[glr-regr18.y:26.13-19: warning: result type clash on merge function `merge': <type2> != <type1>
|
||||
glr-regr18.y:25.18-24: warning: first declaration
|
||||
])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
Reference in New Issue
Block a user