style: rename stmtMerge as stmt_merge
[bison.git] / tests / input.at
blob632be1a3840775999ca3abcc769dad7f250bc74b
1 # Checking the Bison reader.                    -*- Autotest -*-
3 # Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 AT_BANNER([[Input Processing.]])
20 # Mostly test that we are robust to mistakes.
23 ## ----------------------------- ##
24 ## Invalid number of arguments.  ##
25 ## ----------------------------- ##
27 AT_SETUP([Invalid number of arguments])
29 AT_BISON_CHECK([], [1], [],
30 [[bison: missing operand
31 Try 'bison --help' for more information.
32 ]])
34 AT_BISON_CHECK([1.y 2.y], [1], [],
35 [[bison: extra operand '2.y'
36 Try 'bison --help' for more information.
37 ]])
39 # For some reason, on some systems we use the system's getopt, not the
40 # one we ship in gnulib.  So we can get two different error messages.
41 # See https://lists.gnu.org/r/bison-patches/2018-10/msg00154.html
42 AT_BISON_CHECK([--skeleton], [1], [], [stderr])
43 AT_CHECK([[sed -e \
44   "s/requires an argument -- skeleton/'--skeleton' requires an argument/" \
45   stderr]], 0,
46 [[bison: option '--skeleton' requires an argument
47 Try 'bison --help' for more information.
48 ]])
50 AT_CLEANUP
54 ## ----------------- ##
55 ## Invalid options.  ##
56 ## ----------------- ##
58 AT_SETUP([Invalid options])
60 AT_DATA([input.y],
61 [[%%
62 exp: '0'
63 ]])
65 # We used to accept these, as -f, --report and others were sharing
66 # their code with -W.
67 AT_BISON_CHECK([-ferror=caret input.y], [1], [], [ignore])
68 AT_BISON_CHECK([--report=error=itemsets input.y], [1], [], [ignore])
70 # We used to accept any character after "-Werror", instead of ensuring
71 # this is "=".
72 AT_BISON_CHECK([-Werror?all input.y], [1], [], [ignore])
74 AT_CLEANUP
77 ## ---------------- ##
78 ## Invalid inputs.  ##
79 ## ---------------- ##
81 # The truly bad guys no human would write, but easily uncovered by
82 # fuzzers.
83 AT_SETUP([Invalid inputs])
85 AT_DATA([input.y],
86 [[%header "\360\000\200\210"
87 \000\001\002\377?
88 "\000"
91 default: 'a' }
93 %a-does-not-exist
96 ]])
97 AT_PERL_REQUIRE([[-pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y]])
99 AT_BISON_CHECK([-fcaret input.y], [1], [], [stderr])
101 # Autotest's diffing, when there are NUL bytes, just reports "binary
102 # files differ".  So don't leave NUL bytes.  And don't leave invalid
103 # mbchars either: escape raw binary.
104 AT_PERL_CHECK([[-p -e 's{([\0\200\210\360\377])}{sprintf "\\x%02x", ord($1)}ge' stderr]], [],
105 [[input.y:1.11: error: invalid null character
106     1 | %header "\xf0\x00\x80\x88"
107       |           ^
108 input.y:2.1-2: error: invalid characters: '\0\001\002\377?'
109     2 | \x00\x01\x02\xff?
110       | ^~
111 input.y:3.2: error: invalid null character
112     3 | "\x00"
113       |  ^
114 input.y:5.1: error: invalid character: '?'
115     5 | ?
116       | ^
117 input.y:6.14: error: invalid character: '}'
118     6 | default: 'a' }
119       |              ^
120 input.y:7.1: error: invalid character: '%'
121     7 | %&
122       | ^
123 input.y:7.2: error: invalid character: '&'
124     7 | %&
125       |  ^
126 input.y:8.1-17: error: invalid directive: '%a-does-not-exist'
127     8 | %a-does-not-exist
128       | ^~~~~~~~~~~~~~~~~
129 input.y:9.1: error: invalid character: '%'
130     9 | %-
131       | ^
132 input.y:9.2: error: invalid character: '-'
133     9 | %-
134       |  ^
135 input.y:10.1-11.0: error: missing '%}' at end of file
136    10 | %{
137       | ^~
140 AT_CLEANUP
143 ## ------------------------ ##
144 ## Invalid inputs with {}.  ##
145 ## ------------------------ ##
147 AT_SETUP([Invalid inputs with {}])
149 # We used to SEGV here.  See
150 # https://lists.gnu.org/r/bug-bison/2005-07/msg00053.html
152 AT_DATA([input.y],
154 %destructor
155 %initial-action
156 %lex-param
157 %parse-param
158 %printer
159 %union
162 AT_BISON_CHECK([input.y], [1], [],
163 [[input.y:3.1-15: error: expected {...} before %initial-action
166 AT_CLEANUP
169 ## -------------------------- ##
170 ## Yacc warnings on symbols.  ##
171 ## -------------------------- ##
173 AT_SETUP([Yacc warnings on symbols])
175 AT_DATA([input.y],
176 [[%nterm exp
177 %token NUM 0x40 "number"
179 exp: "number";
182 AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
183 [[input.y:1.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
184     1 | %nterm exp
185       | ^~~~~~
186 input.y:2.12-15: warning: POSIX Yacc does not support hexadecimal literals [-Wyacc]
187     2 | %token NUM 0x40 "number"
188       |            ^~~~
189 input.y:2.17-24: warning: POSIX Yacc does not support string literals [-Wyacc]
190     2 | %token NUM 0x40 "number"
191       |                 ^~~~~~~~
192 input.y:4.6-13: warning: POSIX Yacc does not support string literals [-Wyacc]
193     4 | exp: "number";
194       |      ^~~~~~~~
197 AT_CLEANUP
200 ## --------------- ##
201 ## Yacc warnings.  ##
202 ## --------------- ##
204 AT_SETUP([Yacc warnings])
206 AT_DATA([input.y],
207 [[%destructor {} <int>
208 %printer {} <int>
209 %type <int> exp a b
211 exp: a b             { $$ = $1 + $2; };
212 a: <int>{ $$ = 42; } { $$ = $1; };
213 b: %empty            { $$ = 42; };
216 AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
217 [[input.y:1.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
218     1 | %destructor {} <int>
219       | ^~~~~~~~~~~
220 input.y:2.1-8: warning: POSIX Yacc does not support %printer [-Wyacc]
221     2 | %printer {} <int>
222       | ^~~~~~~~
223 input.y:6.9-20: warning: POSIX Yacc does not support typed midrule actions [-Wyacc]
224     6 | a: <int>{ $$ = 42; } { $$ = $1; };
225       |         ^~~~~~~~~~~~
226 input.y:7.4-9: warning: POSIX Yacc does not support %empty [-Wyacc]
227     7 | b: %empty            { $$ = 42; };
228       |    ^~~~~~
231 AT_CLEANUP
234 ## -------------- ##
235 ## Yacc's %type.  ##
236 ## -------------- ##
238 AT_SETUP([Yacc's %type])
240 AT_DATA([input.y],
241 [[%token TOKEN1
242 %nterm nterm1
243 %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
244 %token TOKEN2
245 %nterm nterm2
247 expr: nterm1 nterm2 nterm3
248 nterm1: TOKEN1
249 nterm2: TOKEN2
250 nterm3: "TOKEN3"
253 AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
254 [[input.y:2.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
255     2 | %nterm nterm1
256       | ^~~~~~
257 input.y:3.14-19: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
258     3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
259       |              ^~~~~~
260 input.y:3.28-35: warning: POSIX Yacc does not support string literals [-Wyacc]
261     3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
262       |                            ^~~~~~~~
263 input.y:3.28-35: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
264     3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
265       |                            ^~~~~~~~
266 input.y:3.58-60: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
267     3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
268       |                                                          ^~~
269 input.y:5.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
270     5 | %nterm nterm2
271       | ^~~~~~
272 input.y:3.21-26: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
273     3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
274       |                     ^~~~~~
275 input.y:10.9-16: warning: POSIX Yacc does not support string literals [-Wyacc]
276    10 | nterm3: "TOKEN3"
277       |         ^~~~~~~~
280 AT_CLEANUP
283 ## ----------------------------- ##
284 ## Invalid symbol declarations.  ##
285 ## ----------------------------- ##
287 AT_SETUP([Invalid symbol declarations])
289 AT_DATA([input.y],
290 [[%nterm expr "expression";
291 %nterm term 123;
292 %nterm fact 124 "factor";
293 %nterm '+' '*';
294 %nterm "number";
295 %token "tok1" 1;
296 %left "tok2" 2;
297 %type "tok3" 3;
299 expr: expr '+' term | term;
300 term: term '*' fact | fact;
301 fact: "number";
304 AT_BISON_CHECK([-fcaret input.y], [1], [],
305 [[input.y:1.13-24: error: nonterminals cannot be given a string alias
306     1 | %nterm expr "expression";
307       |             ^~~~~~~~~~~~
308 input.y:2.13-15: error: nonterminals cannot be given a token code
309     2 | %nterm term 123;
310       |             ^~~
311 input.y:3.13-15: error: nonterminals cannot be given a token code
312     3 | %nterm fact 124 "factor";
313       |             ^~~
314 input.y:3.17-24: error: nonterminals cannot be given a string alias
315     3 | %nterm fact 124 "factor";
316       |                 ^~~~~~~~
317 input.y:4.8-10: error: character literals cannot be nonterminals
318     4 | %nterm '+' '*';
319       |        ^~~
320 input.y:5.8-15: error: expected character literal or identifier or <tag> before string
321     5 | %nterm "number";
322       |        ^~~~~~~~
323 input.y:6.8-13: error: expected character literal or identifier or <tag> before string
324     6 | %token "tok1" 1;
325       |        ^~~~~~
326 input.y:7.14: error: unexpected integer literal
327     7 | %left "tok2" 2;
328       |              ^
329 input.y:8.14: error: unexpected integer literal
330     8 | %type "tok3" 3;
331       |              ^
334 AT_CLEANUP
337 ## ---------------------------- ##
338 ## Redefining the error token.  ##
339 ## ---------------------------- ##
341 AT_SETUP([Redefining the error token])
343 # We used to crash when trying to display the original definition of
344 # "error", which is a builtin without any location.
345 AT_BISON_OPTION_PUSHDEFS
347 AT_DATA([input.y],
348 [[%token error 123
349 %token error 124
351 exp:
354 AT_BISON_CHECK([-fcaret input.y], [1], [],
355 [[input.y:2.8-12: warning: symbol error redeclared [-Wother]
356     2 | %token error 124
357       |        ^~~~~
358 input.y:1.8-12: note: previous declaration
359     1 | %token error 123
360       |        ^~~~~
361 input.y:2.14-16: error: redefining code of token error
362     2 | %token error 124
363       |              ^~~
366 # While at it, make sure we properly used the user's number for
367 # "error".  I don't see what it buys us, but...
368 AT_DATA([input.y],
369 [[%{
370 #include <assert.h>
371 #include <stdio.h>
372 ]AT_YYERROR_DEFINE[
373 ]AT_YYLEX_DEFINE[
376 %token error 123
378 exp:
380 int main (void)
382   assert (YYerror == 123);
383   assert (YYTRANSLATE (YYEOF) == YYSYMBOL_YYEOF);
384   assert (YYTRANSLATE (YYerror) == YYSYMBOL_YYerror);
385   assert (YYTRANSLATE (YYUNDEF) == YYSYMBOL_YYUNDEF);
386   return 0;
390 AT_FULL_COMPILE([input])
391 AT_PARSER_CHECK([input], 0)
393 AT_BISON_OPTION_POPDEFS
394 AT_CLEANUP
397 ## ------------------ ##
398 ## Dangling aliases.  ##
399 ## ------------------ ##
401 AT_SETUP([Dangling aliases])
403 AT_DATA([input.y],
404 [[%token FOO "foo"
405 %type <val> "bar"
407 expr: "foo" "bar" "baz"
410 AT_BISON_CHECK([-fcaret -Wdangling input.y], [0], [],
411 [[input.y:2.13-17: warning: string literal "bar" not attached to a symbol [-Wdangling-alias]
412     2 | %type <val> "bar"
413       |             ^~~~~
414 input.y:4.19-23: warning: string literal "baz" not attached to a symbol [-Wdangling-alias]
415     4 | expr: "foo" "bar" "baz"
416       |                   ^~~~~
419 AT_CLEANUP
422 ## --------------------- ##
423 ## Symbol declarations.  ##
424 ## --------------------- ##
426 # Check the parsing of %token, %nterm, %type and %left...
427 AT_SETUP([Symbol declarations])
429 AT_DATA([dump-symbols.m4],
430 [[m4@&t@_define([b4_api_PREFIX], [YY])
432 m4@&t@_define([b4_symbol_dump],
433 [$1, d@&t@nl
434 b4_symbol_if([$1], [is_token], [Token], [Nonterminal]), d@&t@nl
435 b4_symbol([$1], [tag]), d@&t@nl
436 b4_symbol([$1], [id]), d@&t@nl
437 b4_symbol([$1], [code]), d@&t@nl
438 b4_symbol([$1], [type]),
441 b4_output_begin([symbols.csv])
442 number, class, tag, id, code, type,
443 b4_symbol_foreach([b4_symbol_dump])d@&t@nl
444 b4_output_end
447 AT_DATA([input.y],
448 [[%token 'a' A1 1 "A1" A2 A3 "A3" A4 4
449       <type_b> 'b' B5 5 "B5" B6 B7 "B8" B9 9
450       <type_c> 'c' C10 10 "C10" C11 C12 "C12" C13 13
452 %left 'd' D20 20 "D20" D21 D22 "D22" D23 23
453       <type_e> 'e' E25 25 "E25" E26 E27 "E28" E29 29
454       <type_f> 'f' F30 30 "F30" F31 F32 "F32" F33 33
456 %type 'g' G40 "D40" G21 G22 G23
457       <type_h> 'h' H25 "H25" H26 H27 "H28" H29
458       <type_i> 'i' I30 "I30" I31 I32 "I32" I33
460 %nterm j60 j61 j62 j63
461       <type_k> k75 k76 k77 k79
462       <type_l> l80 l81 l82 l83
464 exp:;
467 AT_BISON_CHECK([-Wno-other -S./dump-symbols.m4 input.y])
468 AT_CHECK([cat symbols.csv], [],
469 [[number, class, tag, id, code, type,
470 0, Token, "end of file", YYEOF, 0, ,
471 1, Token, error, YYerror, 256, ,
472 2, Token, "invalid token", YYUNDEF, 257, ,
473 3, Token, 'a', , 97, ,
474 4, Token, "A1", A1, 1, ,
475 5, Token, A2, A2, 258, ,
476 6, Token, "A3", A3, 259, ,
477 7, Token, A4, A4, 4, ,
478 8, Token, 'b', , 98, type_b,
479 9, Token, "B5", B5, 5, type_b,
480 10, Token, B6, B6, 260, type_b,
481 11, Token, "B8", B7, 261, type_b,
482 12, Token, B9, B9, 9, type_b,
483 13, Token, 'c', , 99, type_c,
484 14, Token, "C10", C10, 10, type_c,
485 15, Token, C11, C11, 262, type_c,
486 16, Token, "C12", C12, 263, type_c,
487 17, Token, C13, C13, 13, type_c,
488 18, Token, 'd', , 100, ,
489 19, Token, D20, D20, 20, ,
490 20, Token, "D20", , 264, ,
491 21, Token, D21, D21, 265, ,
492 22, Token, D22, D22, 266, ,
493 23, Token, "D22", , 267, ,
494 24, Token, D23, D23, 23, ,
495 25, Token, 'e', , 101, type_e,
496 26, Token, E25, E25, 25, type_e,
497 27, Token, "E25", , 268, type_e,
498 28, Token, E26, E26, 269, type_e,
499 29, Token, E27, E27, 270, type_e,
500 30, Token, "E28", , 271, type_e,
501 31, Token, E29, E29, 29, type_e,
502 32, Token, 'f', , 102, type_f,
503 33, Token, F30, F30, 30, type_f,
504 34, Token, "F30", , 272, type_f,
505 35, Token, F31, F31, 273, type_f,
506 36, Token, F32, F32, 274, type_f,
507 37, Token, "F32", , 275, type_f,
508 38, Token, F33, F33, 33, type_f,
509 39, Token, 'g', , 103, ,
510 40, Token, "D40", , 276, ,
511 41, Token, 'h', , 104, type_h,
512 42, Token, "H25", , 277, type_h,
513 43, Token, "H28", , 278, type_h,
514 44, Token, 'i', , 105, type_i,
515 45, Token, "I30", , 279, type_i,
516 46, Token, "I32", , 280, type_i,
517 47, Nonterminal, $accept, , -1, ,
518 48, Nonterminal, exp, exp, -1, ,
521 AT_CLEANUP
524 ## ------------ ##
525 ## Invalid $n.  ##
526 ## ------------ ##
528 AT_SETUP([Invalid $n and @n])
530 AT_DATA([input.y],
531 [[%%
532 exp: %empty { $$ = $1 ; };
533 exp: %empty { @$ = @1 ; };
536 AT_BISON_CHECK([-fcaret input.y], [1], [],
537 [[input.y:2.20-21: error: integer out of range: '$1'
538     2 | exp: %empty { $$ = $1 ; };
539       |                    ^~
540 input.y:3.20-21: error: integer out of range: '@1'
541     3 | exp: %empty { @$ = @1 ; };
542       |                    ^~
545 AT_CLEANUP
548 ## -------------- ##
549 ## Type Clashes.  ##
550 ## -------------- ##
552 AT_SETUP([Type Clashes])
554 AT_DATA([input.y],
555 [[%union { int bar; }
556 %token foo
557 %type <bar> exp
559 exp: foo { $$; } foo { $2; } foo
560    | foo
561    | %empty
562    ;
565 AT_BISON_CHECK([-fcaret input.y], [1], [],
566 [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type
567     5 | exp: foo { $$; } foo { $2; } foo
568       |            ^~
569 input.y:5.24-25: error: $2 of 'exp' has no declared type
570     5 | exp: foo { $$; } foo { $2; } foo
571       |                        ^~
572 input.y:5.6-32: warning: type clash on default action: <bar> != <> [-Wother]
573     5 | exp: foo { $$; } foo { $2; } foo
574       |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
575 input.y:6.6-8: warning: type clash on default action: <bar> != <> [-Wother]
576     6 |    | foo
577       |      ^~~
578 input.y:7.6-11: warning: empty rule for typed nonterminal, and no action [-Wother]
579     7 |    | %empty
580       |      ^~~~~~
583 AT_CLEANUP
586 # _AT_UNUSED_VALUES_DECLARATIONS()
587 # --------------------------------
588 # Generate the token, type, and destructor
589 # declarations for the unused values tests.
590 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
591 [[[%token <integer> INT;
592 %type <integer> a b c d e f g h i j k l m n o;
593 %destructor { destroy ($$); } <integer>;]]])
596 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
597 # ----------------------------------------------------------------
598 # Generate a grammar to test unused values, and compile it.  If
599 # DECLARATIONS_AFTER is set, then the token, type, and destructor
600 # declarations are generated after the rules rather than before.  If
601 # CHECK_MIDRULE_VALUES is set, then --warnings=midrule-values is set.
602 m4_define([AT_CHECK_UNUSED_VALUES],
603 [AT_DATA([input.y],
604 m4_ifval([$1], [
607 ], [_AT_UNUSED_VALUES_DECLARATIONS
608 ])[[%%
609 start:
610   'a' a { $][2; } | 'b' b { $][2; } | 'c' c { $][2; } | 'd' d { $][2; }
611 | 'e' e { $][2; } | 'f' f { $][2; } | 'g' g { $][2; } | 'h' h { $][2; }
612 | 'i' i { $][2; } | 'j' j { $][2; } | 'k' k { $][2; } | 'l' l { $][2; }
613 | 'm' m { $][2; } | 'n' n { $][2; } | 'o' o { $][2; }
616 a: INT | INT { } INT { } INT { };
617 b: INT | %empty;
618 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
619 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
620 e: INT | INT { } INT {  } INT { $][1; };
621 f: INT | INT { } INT {  } INT { $][$ = $][1 + $][3 + $][5; };
622 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
623 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
624 i: INT | INT INT { } { $][$ = $][1 + $][2; };
625 j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
626 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
627 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };
628 m: INT | INT <integer>{ $][$ = $][1; } INT <integer>{ $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; };
629 n: INT | INT <integer>{ } INT <integer>{ } INT { };
630 o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
631 ]]m4_ifval([$1], [
632 _AT_UNUSED_VALUES_DECLARATIONS])
635 AT_BISON_CHECK(m4_ifval([$2], [--warnings=midrule-values ])[-fcaret input.y],
636                [0], [],
637 [[input.y:12.10-32: warning: unset value: $][$ [-Wother]
638    12 | a: INT | INT { } INT { } INT { };
639       |          ^~~~~~~~~~~~~~~~~~~~~~~
640 input.y:12.10-12: warning: unused value: $][1 [-Wother]
641    12 | a: INT | INT { } INT { } INT { };
642       |          ^~~
643 input.y:12.18-20: warning: unused value: $][3 [-Wother]
644    12 | a: INT | INT { } INT { } INT { };
645       |                  ^~~
646 input.y:12.26-28: warning: unused value: $][5 [-Wother]
647    12 | a: INT | INT { } INT { } INT { };
648       |                          ^~~
649 input.y:13.10-15: warning: empty rule for typed nonterminal, and no action [-Wother]
650    13 | b: INT | %empty;
651       |          ^~~~~~
652 ]]m4_ifval([$2], [[[input.y:14.14-20: warning: unset value: $][$ [-Wmidrule-values]
653    14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
654       |              ^~~~~~~
655 input.y:14.26-41: warning: unset value: $][$ [-Wmidrule-values]
656    14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
657       |                          ^~~~~~~~~~~~~~~~
658 ]]])[[input.y:14.10-62: warning: unset value: $][$ [-Wother]
659    14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
660       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
661 input.y:14.22-24: warning: unused value: $][3 [-Wother]
662    14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
663       |                      ^~~
664 input.y:14.43-45: warning: unused value: $][5 [-Wother]
665    14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
666       |                                           ^~~
667 ]]m4_ifval([$2], [[[input.y:15.14-16: warning: unset value: $][$ [-Wmidrule-values]
668    15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
669       |              ^~~
670 ]]])[[input.y:15.10-49: warning: unset value: $][$ [-Wother]
671    15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
672       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
673 input.y:15.18-20: warning: unused value: $][3 [-Wother]
674    15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
675       |                  ^~~
676 input.y:15.30-32: warning: unused value: $][5 [-Wother]
677    15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
678       |                              ^~~
679 input.y:16.10-37: warning: unset value: $][$ [-Wother]
680    16 | e: INT | INT { } INT {  } INT { $][1; };
681       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
682 input.y:16.18-20: warning: unused value: $][3 [-Wother]
683    16 | e: INT | INT { } INT {  } INT { $][1; };
684       |                  ^~~
685 input.y:16.27-29: warning: unused value: $][5 [-Wother]
686    16 | e: INT | INT { } INT {  } INT { $][1; };
687       |                           ^~~
688 input.y:18.10-58: warning: unset value: $][$ [-Wother]
689    18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
690       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
691 input.y:18.10-12: warning: unused value: $][1 [-Wother]
692    18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
693       |          ^~~
694 ]]m4_ifval([$2], [[[input.y:18.14-29: warning: unused value: $][2 [-Wmidrule-values]
695    18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
696       |              ^~~~~~~~~~~~~~~~
697 ]]])[[input.y:18.31-33: warning: unused value: $][3 [-Wother]
698    18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
699       |                               ^~~
700 ]]m4_ifval([$2], [[[input.y:18.35-50: warning: unused value: $][4 [-Wmidrule-values]
701    18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
702       |                                   ^~~~~~~~~~~~~~~~
703 ]]])[[input.y:18.52-54: warning: unused value: $][5 [-Wother]
704    18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
705       |                                                    ^~~
706 input.y:19.10-72: warning: unset value: $][$ [-Wother]
707    19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
708       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
709 input.y:19.10-12: warning: unused value: $][1 [-Wother]
710    19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
711       |          ^~~
712 input.y:19.31-33: warning: unused value: $][3 [-Wother]
713    19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
714       |                               ^~~
715 ]]m4_ifval([$2], [[[input.y:19.35-64: warning: unused value: $][4 [-Wmidrule-values]
716    19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
717       |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
718 ]]])[[input.y:19.66-68: warning: unused value: $][5 [-Wother]
719    19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
720       |                                                                  ^~~
721 ]]m4_ifval([$2], [[[input.y:21.18-37: warning: unused value: $][3 [-Wmidrule-values]
722    21 | j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
723       |                  ^~~~~~~~~~~~~~~~~~~~
724 ]]])[[input.y:22.10-68: warning: unset value: $][$ [-Wother]
725    22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
726       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727 input.y:22.10-12: warning: unused value: $][1 [-Wother]
728    22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
729       |          ^~~
730 input.y:22.14-16: warning: unused value: $][2 [-Wother]
731    22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
732       |              ^~~
733 ]]m4_ifval([$2], [[[input.y:22.35-64: warning: unused value: $][4 [-Wmidrule-values]
734    22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
735       |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
736 ]]])[[input.y:25.23-25: warning: unset value: $][$ [-Wother]
737    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
738       |                       ^~~
739 input.y:25.40-42: warning: unset value: $][$ [-Wother]
740    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
741       |                                        ^~~
742 input.y:25.10-50: warning: unset value: $][$ [-Wother]
743    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
744       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
745 input.y:25.10-12: warning: unused value: $][1 [-Wother]
746    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
747       |          ^~~
748 input.y:25.23-25: warning: unused value: $][2 [-Wother]
749    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
750       |                       ^~~
751 input.y:25.27-29: warning: unused value: $][3 [-Wother]
752    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
753       |                           ^~~
754 input.y:25.40-42: warning: unused value: $][4 [-Wother]
755    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
756       |                                        ^~~
757 input.y:25.44-46: warning: unused value: $][5 [-Wother]
758    25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
759       |                                            ^~~
760 input.y:26.23-25: warning: unset value: $][$ [-Wother]
761    26 | o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
762       |                       ^~~
763 input.y:26.40-42: warning: unset value: $][$ [-Wother]
764    26 | o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
765       |                                        ^~~
770 ## --------------- ##
771 ## Unused values.  ##
772 ## --------------- ##
774 AT_SETUP([Unused values])
775 AT_CHECK_UNUSED_VALUES
776 AT_CHECK_UNUSED_VALUES(, [1])
777 AT_CLEANUP
780 ## ------------------------------------------ ##
781 ## Unused values before symbol declarations.  ##
782 ## ------------------------------------------ ##
784 AT_SETUP([Unused values before symbol declarations])
785 AT_CHECK_UNUSED_VALUES([1])
786 AT_CHECK_UNUSED_VALUES([1], [1])
787 AT_CLEANUP
790 ## ------------------- ##
791 ## Symbol redeclared.  ##
792 ## ------------------- ##
794 AT_SETUP([Symbol redeclared])
796 AT_DATA([[input.y]],
797 [[%token FOO FOO
798 %token BAR 12 BAR 12
799 %token EOF 0 EOF 0
801 exp: FOO BAR
804 AT_BISON_CHECK([-fcaret input.y], [0], [],
805 [[input.y:1.12-14: warning: symbol FOO redeclared [-Wother]
806     1 | %token FOO FOO
807       |            ^~~
808 input.y:1.8-10: note: previous declaration
809     1 | %token FOO FOO
810       |        ^~~
811 input.y:2.15-17: warning: symbol BAR redeclared [-Wother]
812     2 | %token BAR 12 BAR 12
813       |               ^~~
814 input.y:2.8-10: note: previous declaration
815     2 | %token BAR 12 BAR 12
816       |        ^~~
817 input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
818     3 | %token EOF 0 EOF 0
819       |              ^~~
820 input.y:3.8-10: note: previous declaration
821     3 | %token EOF 0 EOF 0
822       |        ^~~
825 AT_CLEANUP
828 ## ---------------- ##
829 ## EOF redeclared.  ##
830 ## ---------------- ##
832 AT_SETUP([EOF redeclared])
834 # We used to crash when redefining a token after having defined EOF.
835 # See https://lists.gnu.org/r/bug-bison/2020-08/msg00008.html.
837 AT_DATA([[input.y]],
838 [[%token FOO BAR FOO 0
840 input: %empty
843 AT_BISON_CHECK([-fcaret input.y], [0], [],
844 [[input.y:1.16-18: warning: symbol FOO redeclared [-Wother]
845     1 | %token FOO BAR FOO 0
846       |                ^~~
847 input.y:1.8-10: note: previous declaration
848     1 | %token FOO BAR FOO 0
849       |        ^~~
852 AT_CLEANUP
855 ## --------------------------- ##
856 ## Symbol class redefinition.  ##
857 ## --------------------------- ##
859 AT_SETUP([Symbol class redefinition])
861 AT_DATA([[input.y]],
862 [[%token FOO
863 %nterm FOO BAR
864 %token BAR
865 %nterm error // The token error cannot be redefined as an nterm.
867 FOO: BAR
868 BAR:
871 AT_BISON_CHECK([-fcaret input.y], [1], [],
872 [[input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
873     2 | %nterm FOO BAR
874       |        ^~~
875 input.y:1.8-10: note: previous definition
876     1 | %token FOO
877       |        ^~~
878 input.y:3.8-10: error: symbol BAR redeclared as a token
879     3 | %token BAR
880       |        ^~~
881 input.y:2.12-14: note: previous definition
882     2 | %nterm FOO BAR
883       |            ^~~
884 input.y:4.8-12: error: symbol error redeclared as a nonterminal
885     4 | %nterm error // The token error cannot be redefined as an nterm.
886       |        ^~~~~
887 input.y:6.1-3: error: rule given for FOO, which is a token
888     6 | FOO: BAR
889       | ^~~
892 AT_CLEANUP
895 ## --------------------------------------------- ##
896 ## Default %printer and %destructor redeclared.  ##
897 ## --------------------------------------------- ##
899 AT_SETUP([Default %printer and %destructor redeclared])
901 # AT_TEST([*])
902 # ------------
903 m4_pushdef([AT_TEST],
904 [AT_DATA([[input.y]],
905 [[%destructor { destroy ($$); } <$1> <$1>
906 %printer { print ($$); } <$1> <$1>
908 %destructor { destroy ($$); } <$1>
909 %printer { print ($$); } <$1>
913 start: %empty;
915 %destructor { destroy ($$); } <$1>;
916 %printer { print ($$); } <$1>;
919 AT_BISON_CHECK([-fcaret input.y], [1], [],
920 [[input.y:1.13-29: error: %destructor redeclaration for <>
921     1 | %destructor { destroy ($$); } <> <>
922       |             ^~~~~~~~~~~~~~~~~
923 input.y:1.13-29: note: previous declaration
924     1 | %destructor { destroy ($$); } <> <>
925       |             ^~~~~~~~~~~~~~~~~
926 input.y:2.10-24: error: %printer redeclaration for <>
927     2 | %printer { print ($$); } <> <>
928       |          ^~~~~~~~~~~~~~~
929 input.y:2.10-24: note: previous declaration
930     2 | %printer { print ($$); } <> <>
931       |          ^~~~~~~~~~~~~~~
932 input.y:4.13-29: error: %destructor redeclaration for <>
933     4 | %destructor { destroy ($$); } <>
934       |             ^~~~~~~~~~~~~~~~~
935 input.y:1.13-29: note: previous declaration
936     1 | %destructor { destroy ($$); } <> <>
937       |             ^~~~~~~~~~~~~~~~~
938 input.y:5.10-24: error: %printer redeclaration for <>
939     5 | %printer { print ($$); } <>
940       |          ^~~~~~~~~~~~~~~
941 input.y:2.10-24: note: previous declaration
942     2 | %printer { print ($$); } <> <>
943       |          ^~~~~~~~~~~~~~~
944 input.y:11.13-29: error: %destructor redeclaration for <>
945    11 | %destructor { destroy ($$); } <>;
946       |             ^~~~~~~~~~~~~~~~~
947 input.y:1.13-29: note: previous declaration
948     1 | %destructor { destroy ($$); } <> <>
949       |             ^~~~~~~~~~~~~~~~~
950 input.y:12.10-24: error: %printer redeclaration for <>
951    12 | %printer { print ($$); } <>;
952       |          ^~~~~~~~~~~~~~~
953 input.y:2.10-24: note: previous declaration
954     2 | %printer { print ($$); } <> <>
955       |          ^~~~~~~~~~~~~~~
959 AT_TEST([], [], [])
960 AT_TEST([], [*], [*])
961 m4_popdef([AT_TEST])
963 AT_CLEANUP
966 ## ---------------------------------------------- ##
967 ## Per-type %printer and %destructor redeclared.  ##
968 ## ---------------------------------------------- ##
970 AT_SETUP([Per-type %printer and %destructor redeclared])
972 AT_DATA([[input.y]],
973 [[%destructor { destroy ($$); } <field1> <field2>
974 %printer { print ($$); } <field1> <field2>
976 %destructor { destroy ($$); } <field1> <field1>
977 %printer { print ($$); } <field2> <field2>
981 start: %empty;
983 %destructor { destroy ($$); } <field2> <field1>;
984 %printer { print ($$); } <field2> <field1>;
987 AT_BISON_CHECK([input.y], [1], [],
988 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
989 input.y:1.13-29: note: previous declaration
990 input.y:4.13-29: error: %destructor redeclaration for <field1>
991 input.y:1.13-29: note: previous declaration
992 input.y:5.10-24: error: %printer redeclaration for <field2>
993 input.y:2.10-24: note: previous declaration
994 input.y:5.10-24: error: %printer redeclaration for <field2>
995 input.y:2.10-24: note: previous declaration
996 input.y:11.13-29: error: %destructor redeclaration for <field2>
997 input.y:1.13-29: note: previous declaration
998 input.y:11.13-29: error: %destructor redeclaration for <field1>
999 input.y:1.13-29: note: previous declaration
1000 input.y:12.10-24: error: %printer redeclaration for <field2>
1001 input.y:2.10-24: note: previous declaration
1002 input.y:12.10-24: error: %printer redeclaration for <field1>
1003 input.y:2.10-24: note: previous declaration
1006 AT_CLEANUP
1009 ## ------------------- ##
1010 ## Undefined symbols.  ##
1011 ## ------------------- ##
1013 AT_SETUP([Undefined symbols])
1015 AT_DATA([[input.y]],
1016 [[%printer {} foo baz
1017 %destructor {} bar
1018 %type <foo> qux
1020 exp: bar;
1023 AT_BISON_CHECK([-fcaret input.y], [1], [],
1024 [[input.y:1.13-15: warning: symbol 'foo' is used, but is not defined as a token and has no rules [-Wother]
1025     1 | %printer {} foo baz
1026       |             ^~~
1027 input.y:1.17-19: warning: symbol 'baz' is used, but is not defined as a token and has no rules [-Wother]
1028     1 | %printer {} foo baz
1029       |                 ^~~
1030 input.y:2.16-18: error: symbol 'bar' is used, but is not defined as a token and has no rules
1031     2 | %destructor {} bar
1032       |                ^~~
1033 input.y:3.13-15: warning: symbol 'qux' is used, but is not defined as a token and has no rules [-Wother]
1034     3 | %type <foo> qux
1035       |             ^~~
1038 AT_CLEANUP
1041 ## ----------------------------------------------------- ##
1042 ## Unassociated types used for a printer or destructor.  ##
1043 ## ----------------------------------------------------- ##
1045 AT_SETUP([Unassociated types used for a printer or destructor])
1047 AT_DATA([[input.y]],
1048 [[%token <type1> tag1
1049 %type <type2> tag2
1051 %printer { } <type1> <type3>
1052 %destructor { } <type2> <type4>
1056 exp: tag1 { $1; }
1057    | tag2 { $1; }
1059 tag2: "a" { $$; }
1062 AT_BISON_CHECK([input.y], [0], [],
1063 [[input.y:4.22-28: warning: type <type3> is used, but is not associated to any symbol [-Wother]
1064 input.y:5.25-31: warning: type <type4> is used, but is not associated to any symbol [-Wother]
1067 AT_CLEANUP
1070 ## --------------------------------- ##
1071 ## Useless printers or destructors.  ##
1072 ## --------------------------------- ##
1074 AT_SETUP([Useless printers or destructors])
1076 # AT_TEST([INPUT], [STDERR])
1077 # --------------------------
1078 m4_pushdef([AT_TEST],
1079 [AT_DATA([[input.y]],
1082 AT_BISON_CHECK([input.y], [0], [], [$2
1083 ])])
1085 AT_TEST([[%token <type1> token1
1086 %token <type2> token2
1087 %token <type3> token3
1088 %token <type4> token4
1089 %token <type5> token51 token52
1090 %token <type6> token61 token62
1091 %token <type7> token7
1093 %printer {} token1
1094 %destructor {} token2
1095 %printer {} token51
1096 %destructor {} token61
1098 %printer {} token7
1100 %printer {} <type1>
1101 %destructor {} <type2>
1102 %printer {} <type3>
1103 %destructor {} <type4>
1105 %printer {} <type5>
1106 %destructor {} <type6>
1108 %destructor {} <type7>
1111 exp: "a";]],
1112 [[input.y:16.13-19: warning: useless %printer for type <type1> [-Wother]
1113 input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]]])
1115 # If everybody is typed, <> is useless.
1116 AT_TEST([[%type <type> exp
1117 %token <type> a
1118 %printer {} <> <*>
1120 exp: a;]],
1121 [[input.y:3.13-14: warning: useless %printer for type <> [-Wother]]])
1123 # If nobody is typed, <*> is useless.
1124 AT_TEST([[%token a
1125 %printer {} <> <*>
1127 exp: a;]],
1128 [[input.y:2.16-18: warning: useless %printer for type <*> [-Wother]]])
1130 m4_popdef([AT_TEST])
1132 AT_CLEANUP
1135 ## ---------------------------------------- ##
1136 ## Unused values with default %destructor.  ##
1137 ## ---------------------------------------- ##
1139 AT_SETUP([Unused values with default %destructor])
1141 AT_DATA([[input.y]],
1142 [[%destructor { destroy ($$); } <>
1143 %type <tag> tagged
1147 start: end end tagged tagged { $<tag>1; $3; } ;
1148 end: { } ;
1149 tagged: { } ;
1152 AT_BISON_CHECK([-fcaret input.y], [0], [],
1153 [[input.y:6.8-45: warning: unset value: $$ [-Wother]
1154     6 | start: end end tagged tagged { $<tag>1; $3; } ;
1155       |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1156 input.y:6.12-14: warning: unused value: $2 [-Wother]
1157     6 | start: end end tagged tagged { $<tag>1; $3; } ;
1158       |            ^~~
1159 input.y:7.6-8: warning: unset value: $$ [-Wother]
1160     7 | end: { } ;
1161       |      ^~~
1164 AT_DATA([[input.y]],
1165 [[%destructor { destroy ($$); } <*>
1166 %type <tag> tagged
1170 start: end end tagged tagged { $<tag>1; $3; } ;
1171 end: { } ;
1172 tagged: { } ;
1175 AT_BISON_CHECK([input.y], [0], [],
1176 [[input.y:6.23-28: warning: unused value: $4 [-Wother]
1177 input.y:8.9-11: warning: unset value: $$ [-Wother]
1180 AT_CLEANUP
1183 ## ----------------------------------------- ##
1184 ## Unused values with per-type %destructor.  ##
1185 ## ----------------------------------------- ##
1187 AT_SETUP([Unused values with per-type %destructor])
1189 AT_DATA([[input.y]],
1190 [[%destructor { destroy ($$); } <field1>
1191 %type <field1> start end
1195 start: end end { $1; } ;
1196 end: { }  ;
1199 AT_BISON_CHECK([-fcaret input.y], [0], [],
1200 [[input.y:6.8-22: warning: unset value: $$ [-Wother]
1201     6 | start: end end { $1; } ;
1202       |        ^~~~~~~~~~~~~~~
1203 input.y:6.12-14: warning: unused value: $2 [-Wother]
1204     6 | start: end end { $1; } ;
1205       |            ^~~
1206 input.y:7.6-8: warning: unset value: $$ [-Wother]
1207     7 | end: { }  ;
1208       |      ^~~
1211 AT_CLEANUP
1214 ## ------------------ ##
1215 ## Duplicate string.  ##
1216 ## ------------------ ##
1219 AT_SETUP([Duplicate string])
1221 AT_BISON_OPTION_PUSHDEFS
1222 AT_DATA([input.y],
1223 [[/* 'Bison -v' used to dump core when two tokens are defined with the same
1224    string, as LE and GE below. */
1226 %token NUM
1227 %token LE "<="
1228 %token GE "<="
1231 exp: '(' exp ')' | NUM ;
1234 AT_BISON_OPTION_POPDEFS
1236 AT_BISON_CHECK([-v -o input.c input.y], 0, [],
1237 [[input.y:6.11-14: warning: symbol "<=" used more than once as a literal string [-Wother]
1240 AT_CLEANUP
1243 ## ------------------ ##
1244 ## Token collisions.  ##
1245 ## ------------------ ##
1247 AT_SETUP([Token collisions])
1249 AT_DATA([[input.y]],
1250 [[%token FOO 42 "foo"
1251          BAR 42 "foo"
1253 exp: FOO BAR;
1256 AT_BISON_CHECK([-fcaret input.y], [1], [],
1257 [[input.y:2.17-21: warning: symbol "foo" used more than once as a literal string [-Wother]
1258     2 |          BAR 42 "foo"
1259       |                 ^~~~~
1260 input.y:2.10-12: error: code 42 reassigned to token BAR
1261     2 |          BAR 42 "foo"
1262       |          ^~~
1263 input.y:1.15-19: note: previous declaration for "foo"
1264     1 | %token FOO 42 "foo"
1265       |               ^~~~~
1268 AT_CLEANUP
1271 ## ---------------------- ##
1272 ## Incompatible Aliases.  ##
1273 ## ---------------------- ##
1275 AT_SETUP([Incompatible Aliases])
1277 m4_pushdef([AT_TEST],
1278 [AT_DATA([input.y], [$1])
1279 AT_BISON_CHECK([-fcaret input.y], [1], [], [$2])
1282 # Use the string-alias first to check the order between "first
1283 # declaration" and second.
1285 AT_TEST([[%token foo "foo"
1286 %type <bar> "foo"
1287 %type <baz> foo
1289 exp: foo;
1291 [[input.y:3.13-15: error: %type redeclaration for foo
1292     3 | %type <baz> foo
1293       |             ^~~
1294 input.y:2.13-17: note: previous declaration
1295     2 | %type <bar> "foo"
1296       |             ^~~~~
1299 AT_TEST([[%token foo "foo"
1300 %printer {bar} "foo"
1301 %printer {baz} foo
1303 exp: foo;
1305 [[input.y:3.10-14: error: %printer redeclaration for foo
1306     3 | %printer {baz} foo
1307       |          ^~~~~
1308 input.y:2.10-14: note: previous declaration
1309     2 | %printer {bar} "foo"
1310       |          ^~~~~
1313 AT_TEST([[%token foo "foo"
1314 %destructor {bar} "foo"
1315 %destructor {baz} foo
1317 exp: foo;
1319 [[input.y:3.13-17: error: %destructor redeclaration for foo
1320     3 | %destructor {baz} foo
1321       |             ^~~~~
1322 input.y:2.13-17: note: previous declaration
1323     2 | %destructor {bar} "foo"
1324       |             ^~~~~
1327 AT_TEST([[%token foo "foo"
1328 %left "foo"
1329 %left foo
1331 exp: foo;
1333 [[input.y:3.1-5: error: %left redeclaration for foo
1334     3 | %left foo
1335       | ^~~~~
1336 input.y:2.1-5: note: previous declaration
1337     2 | %left "foo"
1338       | ^~~~~
1341 # This time, declare the alias after its use.
1343 # Precedence/associativity.
1344 AT_TEST([[%left "foo"
1345 %left foo
1346 %token foo "foo"
1348 exp: foo;
1350 [[input.y:2.1-5: error: %left redeclaration for foo
1351     2 | %left foo
1352       | ^~~~~
1353 input.y:1.1-5: note: previous declaration
1354     1 | %left "foo"
1355       | ^~~~~
1358 # Printer.
1359 AT_TEST([[%printer {} "foo"
1360 %printer {} foo
1361 %token foo "foo"
1363 exp: foo;
1365 [[input.y:2.10-11: error: %printer redeclaration for foo
1366     2 | %printer {} foo
1367       |          ^~
1368 input.y:1.10-11: note: previous declaration
1369     1 | %printer {} "foo"
1370       |          ^~
1373 # Destructor.
1374 AT_TEST([[%destructor {} "foo"
1375 %destructor {} foo
1376 %token foo "foo"
1378 exp: foo;
1380 [[input.y:2.13-14: error: %destructor redeclaration for foo
1381     2 | %destructor {} foo
1382       |             ^~
1383 input.y:1.13-14: note: previous declaration
1384     1 | %destructor {} "foo"
1385       |             ^~
1388 m4_popdef([AT_TEST])
1389 AT_CLEANUP
1393 ## ----------------------- ##
1394 ## Torturing the Scanner.  ##
1395 ## ----------------------- ##
1397 # Be sure to compile and run, so that the C compiler checks what
1398 # we do.
1400 AT_SETUP([Torturing the Scanner])
1402 AT_BISON_OPTION_PUSHDEFS
1404 AT_DATA([input.y],
1407 AT_BISON_CHECK([-fcaret  input.y], [1], [],
1408 [[input.y:1.1-2: error: unexpected {...}
1409     1 | {}
1410       | ^~
1414 # Clang chokes on some of our comments, because it tries to "parse"
1415 # some documentation directives in the comments:
1417 # input.c:166:50: error: '\a' command does not have a valid word argument [-Werror,-Wdocumentation]
1418 #     FAKE = 258                     /* "fake [] \a\b\f\n\r\t\v\"'?\\[\\ ??!??'??(??)??-??/??<??=??> \001\001"  */
1419 #                                                ~~^
1420 AT_DATA_GRAMMAR([input.y],
1421 [[%code requires {
1422 #if defined __clang__ && 10 <= __clang_major__
1423 # pragma clang diagnostic ignored "-Wdocumentation"
1424 #endif
1428 /* This is seen in GCC: a %{ and %} in middle of a comment. */
1429 const char *foo = "So %{ and %} can be here too.";
1431 #if 0
1432 /* These examples test Bison while not stressing C compilers too much.
1433    Many C compilers mishandle backslash-newlines, so this part of the
1434    test is inside "#if 0".  The comment and string are written so that
1435    the "#endif" will be seen regardless of the C compiler bugs that we
1436    know about, namely:
1438      HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
1439      comment.
1441      The Apple Darwin compiler (as of late 2002) mishandles
1442      \\[newline]' within a character constant.
1444    */
1447 * A comment with backslash-newlines in it. %} *\
1450 /* { Close the above comment, if the C compiler mishandled it.  */
1452 char str[] = "\\
1453 " A string with backslash-newlines in it %{ %} \\
1457 char apostrophe = '\'';
1458 #endif
1460 #include <stdio.h>
1461 #include <stdlib.h>
1462 #include <assert.h>
1464 /* %{ and %} can be here too. */
1467 /* Exercise pre-prologue dependency to %union.  */
1468 typedef int value;
1471 /* Exercise M4 quoting: '@:>@@:>@', 0.  */
1473 /* Also exercise %union. */
1474 %union
1476   value ival; /* A comment to exercise an old bug. */
1480 /* Exercise post-prologue dependency to %union.  */
1482 static YYSTYPE value_as_yystype (value val);
1484 /* Exercise quotes in declarations.  */
1485 char quote[] = "@:>@@:>@,";
1489 ]AT_YYERROR_DECLARE[
1490 ]AT_YYLEX_DECLARE[
1493 %type <ival> '@<:@'
1495 /* Exercise quotes in strings.  */
1496 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
1498 /* Beware of the generated comments that embed string aliases that
1499    might close the comment.  */
1500 %token COMMENT_CLOSE "*/"
1501 %token COMMENT       "/* comment */"
1504 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1.  */
1505 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
1506   {
1507     /* Exercise quotes in braces.  */
1508     char tmp[] = "@<:@%c@:>@,\n";
1509     printf (tmp, $1);
1510   }
1513 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
1514 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
1515 output.or.oline.opt: %empty;|oline;;|output;;;
1516 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
1518 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2.  */
1520 static YYSTYPE
1521 value_as_yystype (value val)
1523   YYSTYPE res;
1524   res.ival = val;
1525   return res;
1527 ]AT_YYERROR_DEFINE[
1528 static int
1529 yylex (void)
1531   static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
1532 #output "; /* "
1533   */
1534   enum { input_elts = sizeof input };
1535   (void) input_elts;
1536   static int toknum;
1537   assert (0 <= toknum && toknum < input_elts);
1538   yylval = value_as_yystype (input[toknum]);
1539   return input[toknum++];
1543 # Pacify Emacs'font-lock-mode: "
1545 AT_DATA([main.c],
1546 [[typedef int value;
1547 #include "input.h"
1549 int yyparse (void);
1550 ]AT_MAIN_DEFINE[
1552 AT_BISON_OPTION_POPDEFS
1554 AT_BISON_CHECK([-d -v -o input.c input.y])
1555 AT_COMPILE([input.o])
1556 AT_COMPILE([main.o])
1557 AT_COMPILE([input], [input.o main.o])
1558 AT_PARSER_CHECK([input], 0,
1559 [[[@<:@],
1562 AT_CLEANUP
1565 ## ---------------------- ##
1566 ## Typed symbol aliases.  ##
1567 ## ---------------------- ##
1569 AT_SETUP([Typed symbol aliases])
1571 # Bison 2.0 broke typed symbol aliases - ensure they work.
1572 AT_BISON_OPTION_PUSHDEFS
1574 AT_DATA_GRAMMAR([input.y],
1575 [[%union
1577   int val;
1579 %token <val> MY_TOKEN "MY TOKEN"
1580 %type <val> exp
1582 exp: "MY TOKEN";
1586 AT_BISON_CHECK([-o input.c input.y])
1588 AT_BISON_OPTION_POPDEFS
1589 AT_CLEANUP
1592 ## --------- ##
1593 ## Require.  ##
1594 ## --------- ##
1596 m4_define([AT_CHECK_REQUIRE],
1597 [AT_SETUP([Require $1])
1598 AT_BISON_OPTION_PUSHDEFS
1599 AT_DATA_GRAMMAR([input.y],
1600 [[%require "$1";
1602 empty_file: %empty;
1604 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
1605 AT_BISON_OPTION_POPDEFS
1606 AT_CLEANUP
1609 AT_CHECK_REQUIRE(1.0, 0)
1610 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
1611 ## FIXME: Some day augment this version number.
1612 AT_CHECK_REQUIRE(100.0, 63)
1615 ## ------------------------------------- ##
1616 ## String aliases for character tokens.  ##
1617 ## ------------------------------------- ##
1619 AT_SETUP([String aliases for character tokens])
1621 # Bison once thought a character token and its alias were different
1622 # symbols with the same code.
1624 AT_BISON_OPTION_PUSHDEFS
1625 AT_DATA_GRAMMAR([input.y],
1626 [[%token 'a' "a"
1628 start: 'a';
1632 AT_BISON_CHECK([-o input.c input.y])
1634 AT_BISON_OPTION_POPDEFS
1635 AT_CLEANUP
1638 ## -------------- ##
1639 ## Symbol names.  ##
1640 ## -------------- ##
1642 AT_SETUP([Symbols])
1644 AT_BISON_OPTION_PUSHDEFS
1645 AT_DATA_GRAMMAR([input.y],
1646 [[%token WITH-DASH
1647 %token WITHOUT_DASH "WITHOUT-DASH"
1648 %token WITH.PERIOD
1649 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
1650 %code {
1651   ]AT_YYERROR_DECLARE[
1652   ]AT_YYLEX_DECLARE[
1655 start: with-dash without_dash with.period without_period;
1656 with-dash: WITH-DASH;
1657 without_dash: "WITHOUT-DASH";
1658 with.period: WITH.PERIOD;
1659 without_period: "WITHOUT.PERIOD";
1661 ]AT_YYERROR_DEFINE[
1662 ]AT_YYLEX_DEFINE[
1665 # POSIX Yacc accept periods, but not dashes.
1666 AT_BISON_CHECK([--yacc input.y], [], [],
1667 [[input.y:1.1-5: warning: POSIX Yacc does not support %code [-Wyacc]
1668 input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
1669 input.y:10.21-34: warning: POSIX Yacc does not support string literals [-Wyacc]
1670 input.y:12.23-38: warning: POSIX Yacc does not support string literals [-Wyacc]
1671 input.y:13.1-5: warning: POSIX Yacc does not support %code [-Wyacc]
1672 input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
1673 input.y:22.15-28: warning: POSIX Yacc does not support string literals [-Wyacc]
1674 input.y:24.17-32: warning: POSIX Yacc does not support string literals [-Wyacc]
1677 # Dashes are fine for GNU Bison.
1678 AT_BISON_CHECK([-o input.c input.y])
1680 # Make sure we don't export silly token identifiers with periods or dashes.
1681 AT_COMPILE([input.o])
1684 # Periods are genuine letters, they can start identifiers.
1685 # Digits and dashes cannot.
1686 AT_DATA_GRAMMAR([input.y],
1687 [[%token .GOOD
1688          -GOOD
1689          1NV4L1D
1690          -123
1692 start: .GOOD GOOD
1694 AT_BISON_CHECK([-o input.c input.y], [1], [],
1695 [[input.y:10.10: error: invalid character: '-'
1696 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
1697 input.y:12.10: error: invalid character: '-'
1700 AT_BISON_OPTION_POPDEFS
1701 AT_CLEANUP
1704 ## ----------------- ##
1705 ## Numbered tokens.  ##
1706 ## ----------------- ##
1708 AT_SETUP([Numbered tokens])
1710 AT_BISON_OPTION_PUSHDEFS
1711 AT_DATA_GRAMMAR([redecl.y],
1712 [[%token DECIMAL_1     11259375
1713          HEXADECIMAL_1 0xabcdef
1714          HEXADECIMAL_2 0xFEDCBA
1715          DECIMAL_2     16702650
1717 start: DECIMAL_1 HEXADECIMAL_2;
1720 AT_BISON_CHECK([redecl.y], [1], [],
1721 [[redecl.y:10.10-22: error: code 11259375 reassigned to token HEXADECIMAL_1
1722 redecl.y:9.8-16: note: previous declaration for DECIMAL_1
1723 redecl.y:12.10-18: error: code 16702650 reassigned to token DECIMAL_2
1724 redecl.y:11.10-22: note: previous declaration for HEXADECIMAL_2
1727 AT_DATA_GRAMMAR([too-large.y],
1728 [[%token TOO_LARGE_DEC 999999999999999999999
1729          TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
1731 start: TOO_LARGE_DEC TOO_LARGE_HEX
1735 AT_BISON_CHECK([too-large.y], [1], [],
1736 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
1737 too-large.y:9.22-42: error: code of token TOO_LARGE_DEC too large
1738 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
1739 too-large.y:10.24-44: error: code of token TOO_LARGE_HEX too large
1742 AT_BISON_OPTION_POPDEFS
1743 AT_CLEANUP
1746 ## --------------------- ##
1747 ## Unclosed constructs.  ##
1748 ## --------------------- ##
1750 AT_SETUP([Unclosed constructs])
1752 # Bison's scan-gram.l once forgot to STRING_FINISH () some unclosed
1753 # constructs, so they were prepended to whatever it STRING_GROW ()'ed
1754 # next.  It also threw them away rather than returning them to the
1755 # parser.  The effect was confusing subsequent error messages.
1757 AT_DATA([input.y],
1758 [[%token A "a
1759 %token B "b"
1760 %token AB "ab" // Used to complain that "ab" was already used.
1761 %token C '1
1762 %token TWO "2"
1763 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
1767 start: %empty;
1769 // Used to report a syntax error because it didn't see any kind of symbol
1770 // identifier.
1771 %type <f> 'a
1773 %type <f> "a
1775 // Used to report a syntax error because it didn't see braced code.
1776 %destructor { free ($$)
1779 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
1780 [[input.y:1.10-2.0: error: missing '"' at end of line
1781     1 | %token A "a
1782       |          ^~
1783 input.y:4.10-5.0: error: missing "'" at end of line
1784     4 | %token C '1
1785       |          ^~
1786 input.y:14.11-15.0: error: missing "'" at end of line
1787    14 | %type <f> 'a
1788       |           ^~
1789 input.y:16.11-17.0: error: missing '"' at end of line
1790    16 | %type <f> "a
1791       |           ^~
1792 input.y:19.13-20.0: error: missing '}' at end of file
1793    19 | %destructor { free ($$)
1794       |             ^~~~~~~~~~~
1795 input.y:20.1: error: unexpected end of file
1798 AT_CLEANUP
1801 ## ------------------------- ##
1802 ## %start after first rule.  ##
1803 ## ------------------------- ##
1805 AT_SETUP([%start after first rule])
1807 # Bison once complained that a %start after the first rule was a
1808 # redeclaration of the start symbol.
1810 AT_DATA([input.y],
1811 [[%%
1812 false_start: %empty;
1813 start: false_start ;
1814 %start start;
1817 AT_BISON_CHECK([-o input.c input.y])
1819 AT_CLEANUP
1822 ## ------------------------- ##
1823 ## Duplicate %start symbol.  ##
1824 ## ------------------------- ##
1826 AT_SETUP([Duplicate %start symbol])
1828 AT_KEYWORDS([multistart])
1830 AT_DATA([input.y],
1831 [[%start exp exp exp
1833 exp: %empty;
1836 AT_BISON_CHECK([-fcaret input.y], [0], [],
1837 [[input.y:1.12-14: warning: duplicate directive [-Wother]
1838     1 | %start exp exp exp
1839       |            ^~~
1840 input.y:1.8-10: note: previous declaration
1841     1 | %start exp exp exp
1842       |        ^~~
1843 input.y:1.16-18: warning: duplicate directive [-Wother]
1844     1 | %start exp exp exp
1845       |                ^~~
1846 input.y:1.8-10: note: previous declaration
1847     1 | %start exp exp exp
1848       |        ^~~
1849 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
1852 AT_DATA([input.y],
1853 [[%start exp foo exp
1855 exp: foo;
1856 foo: %empty;
1859 AT_BISON_CHECK([-fcaret input.y], [0], [],
1860 [[input.y:1.16-18: warning: duplicate directive [-Wother]
1861     1 | %start exp foo exp
1862       |                ^~~
1863 input.y:1.8-10: note: previous declaration
1864     1 | %start exp foo exp
1865       |        ^~~
1866 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
1869 AT_DATA([input.y],
1870 [[%start exp foo
1871 %start exp
1873 exp: foo;
1874 foo: %empty;
1877 AT_BISON_CHECK([-fcaret input.y], [0], [],
1878 [[input.y:2.8-10: warning: duplicate directive [-Wother]
1879     2 | %start exp
1880       |        ^~~
1881 input.y:1.8-10: note: previous declaration
1882     1 | %start exp foo
1883       |        ^~~
1884 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
1888 AT_CLEANUP
1891 ## --------------------- ##
1892 ## %prec takes a token.  ##
1893 ## --------------------- ##
1895 AT_SETUP([%prec takes a token])
1897 # Bison once allowed %prec sym where sym was a nonterminal.
1899 AT_DATA([input.y],
1900 [[%%
1901 start: PREC %prec PREC ;
1902 PREC: %empty;
1905 AT_BISON_CHECK([input.y], [1], [],
1906 [[input.y:3.1-4: error: rule given for PREC, which is a token
1909 AT_CLEANUP
1912 ## ------------------------------- ##
1913 ## %prec's token must be defined.  ##
1914 ## ------------------------------- ##
1916 AT_SETUP([[%prec's token must be defined]])
1918 # According to POSIX, a %prec token must be defined separately.
1920 AT_DATA([[input.y]],
1921 [[%%
1922 start: %prec PREC ;
1925 AT_BISON_CHECK([[input.y]], [[0]], [],
1926 [[input.y:2.8-17: warning: token for %prec is not defined: PREC [-Wother]
1929 AT_CLEANUP
1932 ## -------------------------------- ##
1933 ## Reject unused %code qualifiers.  ##
1934 ## -------------------------------- ##
1936 AT_SETUP([Reject unused %code qualifiers])
1938 AT_DATA([input-c.y],
1939 [[%code q {}
1940 %code bad {}
1941 %code bad {}
1942 %code format {}
1944 start: %empty;
1946 AT_BISON_CHECK([[input-c.y]], [[1]], [],
1947 [[input-c.y:1.7: error: %code qualifier 'q' is not used
1948 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
1949 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
1950 input-c.y:4.7-12: error: %code qualifier 'format' is not used
1953 AT_DATA([input-c-glr.y],
1954 [[%code q {}
1955 %code bad {}
1956  %code bad {}
1958 start: %empty;
1960 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
1961 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
1962 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
1963 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
1966 AT_DATA([input-c++.y],
1967 [[%code q {}
1968 %code bad {}
1969  %code q {}
1971 start: %empty;
1973 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
1974 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
1975 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
1976 input-c++.y:3.8: error: %code qualifier 'q' is not used
1979 AT_DATA([input-c++-glr.y],
1980 [[%code bad {}
1981 %code q {}
1982 %code q {}
1984 start: %empty;
1986 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
1987 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
1988 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
1989 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
1992 AT_DATA([special-char-@@.y],
1993 [[%code bad {}
1994 %code q {}
1995 %code q {}
1997 start: %empty;
1999 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
2000 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
2001 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
2002 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
2005 AT_DATA([special-char-@:>@.y],
2006 [[%code bad {}
2007 %code q {}
2008 %code q {}
2010 start: %empty;
2012 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
2013 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
2014 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
2015 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
2018 AT_CLEANUP
2021 ## ---------------- ##
2022 ## Multiple %code.  ##
2023 ## ---------------- ##
2025 AT_SETUP([Multiple %code])
2027 # Make sure that repeated arguments to %code are separated by
2028 # end-of-lines.  At some point, a missing eol would leave synclines
2029 # appended to the previous value.  Here, we use CPP directive to
2030 # introduce dependency on the absence/presence of the eol.
2031 AT_BISON_OPTION_PUSHDEFS
2033 AT_DATA([input.y],
2034 [[%code {#include <assert.h>}
2035 %code {#define A B}
2036 %code {#define B C}
2037 %code {#define C D}
2038 %code {#define D 42}
2039 %code {
2040   ]AT_YYERROR_DECLARE[
2041   ]AT_YYLEX_DECLARE[
2044 start: %empty;
2046 ]AT_YYERROR_DEFINE[
2047 ]AT_YYLEX_DEFINE[
2048 int main (void)
2050   assert (A == 42);
2051   return 0;
2054 AT_FULL_COMPILE([input])
2055 AT_PARSER_CHECK([input])
2057 AT_BISON_OPTION_POPDEFS
2058 AT_CLEANUP
2061 ## ---------------- ##
2062 ## %define errors.  ##
2063 ## ---------------- ##
2065 AT_SETUP([%define errors])
2067 AT_DATA([input-redefined.y],
2068 [[%define var "value1"
2069 %define var "value1"
2070  %define var "value2"
2071 %define special1 "@:>@"
2072 %define special2 "@<:@"
2074 start: %empty;
2077 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
2078 [[input-redefined.y:2.1-20: warning: %define variable 'var' redefined [-Wother]
2079 input-redefined.y:1.1-20: note: previous definition
2080 input-redefined.y:3.2-21: error: %define variable 'var' redefined
2081 input-redefined.y:2.1-20: note: previous definition
2082 input-redefined.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
2085 AT_DATA([input-unused.y],
2086 [[%define var "value"
2088 start: %empty;
2091 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
2092 [[input-unused.y:1.1-19: error: %define variable 'var' is not used
2095 AT_CLEANUP
2098 ## ----------------------------------- ##
2099 ## %define, --define, --force-define.  ##
2100 ## ----------------------------------- ##
2102 AT_SETUP([[%define, --define, --force-define]])
2104 AT_DATA([[skel.c]],
2105 [[m4@&t@_divert_push(0)@
2106 @output(b4_parser_file_name@)@
2107 [var-dd: ]b4_percent_define_get([[var-dd]])[
2108 var-ff: ]b4_percent_define_get([[var-ff]])[
2109 var-dfg: ]b4_percent_define_get([[var-dfg]])[
2110 var-fd: ]b4_percent_define_get([[var-fd]])
2111 m4@&t@_divert_pop(0)
2113 AT_DATA([[input.y]],
2114 [[%define var-dfg "gram"
2116 start: %empty;
2118 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
2119                  -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
2120                  -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
2121                  -Fvar-fd=cmd-f -Dvar-fd=cmd-d   \
2122                  --skeleton ./skel.c input.y]])
2123 AT_CHECK([[cat input.tab.c]], [[0]],
2124 [[var-dd: cmd-d2
2125 var-ff: cmd-f2
2126 var-dfg: cmd-f
2127 var-fd: cmd-d
2130 AT_DATA([[input-dg.y]],
2131 [[%define var "gram"
2133 start: %empty;
2135 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
2136 [[input-dg.y:1.1-18: error: %define variable 'var' redefined
2137 <command line>:3: note: previous definition
2138 input-dg.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
2141 AT_DATA([[input-dg.y]],
2142 [[%define var "gram"
2144 start: %empty;
2146 AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
2147 [[input-dg.y:1.1-18: error: %define variable 'var' redefined
2148     1 | %define var "gram"
2149       | ^~~~~~~~~~~~~~~~~~
2150 <command line>:4: note: previous definition
2151 input-dg.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
2154 AT_DATA([[input-unused.y]],
2155 [[%%
2156 start: %empty;
2158 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
2159 [[<command line>:3: error: %define variable 'unused-d' is not used
2160 <command line>:4: error: %define variable 'unused-f' is not used
2163 AT_CLEANUP
2166 ## --------------------------- ##
2167 ## %define Boolean variables.  ##
2168 ## --------------------------- ##
2170 AT_SETUP([["%define" Boolean variables]])
2172 AT_DATA([Input.y],
2173 [[%language "Java"
2174 %define api.parser.class {Input}
2175 %define api.parser.public {maybe}
2177 start: %empty;
2180 AT_BISON_CHECK([[Input.y]], [1], [],
2181 [[Input.y:3.1-33: error: invalid value for %define Boolean variable 'api.parser.public'
2184 AT_CLEANUP
2187 ## ------------------------ ##
2188 ## %define code variables.  ##
2189 ## ------------------------ ##
2191 AT_SETUP([["%define" code variables]])
2193 m4_pushdef([AT_TEST],
2194 [AT_DATA([input.yy],
2195 [[%skeleton "lalr1.cc" %locations
2196 %define api.location.type ]$1[quux]$2[
2197 %define api.namespace     ]$1[quux]$2[
2198 %define api.prefix        ]$1[quux]$2[
2199 %define api.token.prefix  ]$1[quux]$2[
2200 %token TOK // Otherwise api.token.prefix is unused.
2202 start: TOK;
2205 AT_BISON_CHECK([[input.yy]], [0], [],
2206 [[input.yy:2.$3: warning: %define variable 'api.location.type' requires '{...}' values [-Wdeprecated]
2207 input.yy:4.$3: warning: %define variable 'api.prefix' requires '{...}' values [-Wdeprecated]
2208 input.yy:5.$3: warning: %define variable 'api.token.prefix' requires '{...}' values [-Wdeprecated]
2209 input.yy:3.$3: warning: %define variable 'api.namespace' requires '{...}' values [-Wdeprecated]
2213 AT_TEST([],  [],  [1-30])
2214 AT_TEST(["], ["], [1-32])
2215 m4_popdef([AT_TEST])
2217 AT_CLEANUP
2220 ## --------------------------- ##
2221 ## %define keyword variables.  ##
2222 ## --------------------------- ##
2224 AT_SETUP([["%define" keyword variables]])
2226 m4_pushdef([AT_TEST],
2227 [AT_DATA([input.y],
2228 [[%define api.pure                ]$1[true]$2[
2229 %define api.push-pull             ]$1[both]$2[
2230 %define lr.default-reduction      ]$1[most]$2[
2231 %define lr.keep-unreachable-state ]$1[true]$2[
2232 %define lr.type                   ]$1[lalr]$2[
2234 exp: %empty
2237 AT_BISON_CHECK([[input.y]], [0], [],
2238 [[input.y:5.1-40: warning: %define variable 'lr.type' requires keyword values [-Wdeprecated]
2239 input.y:3.1-40: warning: %define variable 'lr.default-reduction' requires keyword values [-Wdeprecated]
2240 input.y:4.1-40: warning: %define variable 'lr.keep-unreachable-state' requires keyword values [-Wdeprecated]
2241 input.y:1.1-38: warning: %define variable 'api.pure' requires keyword values [-Wdeprecated]
2242 input.y:2.1-40: warning: %define variable 'api.push-pull' requires keyword values [-Wdeprecated]
2246 AT_TEST(["], ["])
2247 AT_TEST([{], [}])
2248 m4_popdef([AT_TEST])
2250 AT_CLEANUP
2253 ## ------------------------ ##
2254 ## %define enum variables.  ##
2255 ## ------------------------ ##
2257 AT_SETUP([["%define" enum variables]])
2259 # Check errors from the front-end, and the back-end.  Since the
2260 # front-end quits before calling the back-end, these tests cannot be
2261 # fused.
2263 # Front-end.
2264 AT_DATA([[input.y]],
2265 [[%define lr.default-reduction bogus
2267 start: %empty;
2269 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2270 [[input.y:1.1-34: error: invalid value for %define variable 'lr.default-reduction': 'bogus'
2271     1 | %define lr.default-reduction bogus
2272       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2273 input.y:1.1-34: note: accepted value: 'most'
2274 input.y:1.1-34: note: accepted value: 'consistent'
2275 input.y:1.1-34: note: accepted value: 'accepting'
2278 # Check escapes.
2279 AT_DATA([[input.y]],
2280 [[%define lr.default-reduction {[$@]}
2282 start: %empty;
2284 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2285 [[input.y:1.1-35: warning: %define variable 'lr.default-reduction' requires keyword values [-Wdeprecated]
2286     1 | %define lr.default-reduction {[$@]}
2287       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2288 input.y:1.1-35: error: invalid value for %define variable 'lr.default-reduction': '[$@]'
2289     1 | %define lr.default-reduction {[$@]}
2290       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2291 input.y:1.1-35: note: accepted value: 'most'
2292 input.y:1.1-35: note: accepted value: 'consistent'
2293 input.y:1.1-35: note: accepted value: 'accepting'
2297 # Back-end.
2298 AT_DATA([[input.y]],
2299 [[%define api.push-pull neither
2301 start: %empty;
2303 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2304 [[input.y:1.1-29: error: invalid value for %define variable 'api.push-pull': 'neither'
2305     1 | %define api.push-pull neither
2306       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2307 input.y:1.1-29: note: accepted value: 'pull'
2308 input.y:1.1-29: note: accepted value: 'push'
2309 input.y:1.1-29: note: accepted value: 'both'
2312 AT_CLEANUP
2316 ## ------------------------ ##
2317 ## %define file variables.  ##
2318 ## ------------------------ ##
2320 AT_SETUP([["%define" file variables]])
2322 AT_DATA([[input.y]],
2323 [[%skeleton "lalr1.cc"
2324 %locations
2325 %define api.location.file {bogus}
2327 start: %empty;
2329 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2330 [[input.y:3.1-33: error: %define variable 'api.location.file' requires 'none' or '"..."' values
2331     3 | %define api.location.file {bogus}
2332       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2335 AT_CLEANUP
2338 ## -------------------------------- ##
2339 ## %define backward compatibility.  ##
2340 ## -------------------------------- ##
2342 AT_SETUP([["%define" backward compatibility]])
2344 # The error messages tell us whether the variables are properly updated.
2345 AT_DATA([[input.y]],
2346 [[%define api.push_pull both
2347 %define lr.keep_unreachable_states maybe
2348 %define namespace "foo"
2349 %define variant
2350 %define parser_class_name {parser}
2351 %define filename_type {filename}
2353 start: %empty;
2355 AT_BISON_CHECK([[-fcaret input.y]], [1], [],
2356 [[input.y:1.1-26: warning: deprecated directive: '%define api.push_pull both', use '%define api.push-pull both' [-Wdeprecated]
2357     1 | %define api.push_pull both
2358       | ^~~~~~~~~~~~~~~~~~~~~~~~~~
2359       | %define api.push-pull both
2360 input.y:2.1-40: warning: deprecated directive: '%define lr.keep_unreachable_states maybe', use '%define lr.keep-unreachable-state maybe' [-Wdeprecated]
2361     2 | %define lr.keep_unreachable_states maybe
2362       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2363       | %define lr.keep-unreachable-state maybe
2364 input.y:3.1-23: warning: deprecated directive: '%define namespace "foo"', use '%define api.namespace {foo}' [-Wdeprecated]
2365     3 | %define namespace "foo"
2366       | ^~~~~~~~~~~~~~~~~~~~~~~
2367       | %define api.namespace {foo}
2368 input.y:4.1-15: warning: deprecated directive: '%define variant', use '%define api.value.type variant' [-Wdeprecated]
2369     4 | %define variant
2370       | ^~~~~~~~~~~~~~~
2371       | %define api.value.type variant
2372 input.y:5.1-34: warning: deprecated directive: '%define parser_class_name {parser}', use '%define api.parser.class {parser}' [-Wdeprecated]
2373     5 | %define parser_class_name {parser}
2374       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2375       | %define api.parser.class {parser}
2376 input.y:6.1-32: warning: deprecated directive: '%define filename_type {filename}', use '%define api.filename.type {filename}' [-Wdeprecated]
2377     6 | %define filename_type {filename}
2378       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2379       | %define api.filename.type {filename}
2380 input.y:2.1-40: error: invalid value for %define Boolean variable 'lr.keep-unreachable-state'
2381     2 | %define lr.keep_unreachable_states maybe
2382       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2383 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
2386 AT_CLEANUP
2389 ## ------------------------- ##
2390 ## Unused %define api.pure.  ##
2391 ## ------------------------- ##
2393 AT_SETUP([[Unused %define api.pure]])
2395 # AT_TEST(DECLS, VALUE, LOCATION)
2396 # -------------------------------
2397 # Make sure Bison reports that '%define api.pure VALUE' is unused when DECLS
2398 # are specified.
2399 m4_pushdef([AT_TEST],
2401 AT_DATA([[input.y]],
2402 [[%define api.pure ]$2[
2403 ]$1[
2405 start: %empty;
2408 AT_BISON_CHECK([[input.y]], [[1]], [],
2409 [[input.y:]$3[: error: %define variable 'api.pure' is not used
2413 AT_TEST([[%language "c++"]],             [[]],      [[1.1-16]])
2414 AT_TEST([[%language "c++"]],             [[false]], [[1.1-22]])
2415 AT_TEST([[%language "c++" %glr-parser]], [[""]],    [[1.1-19]])
2416 AT_TEST([[%language "c++" %glr-parser]], [[false]], [[1.1-22]])
2417 AT_TEST([[%language "java"]],            [[true]],  [[1.1-21]])
2418 AT_TEST([[%language "java"]],            [[false]], [[1.1-22]])
2420 m4_popdef([AT_TEST])
2422 AT_CLEANUP
2425 ## -------------------------------- ##
2426 ## C++ namespace reference errors.  ##
2427 ## -------------------------------- ##
2429 AT_SETUP([[C++ namespace reference errors]])
2431 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
2432 # -------------------------------------------------------------
2433 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
2434 m4_define([AT_CHECK_NAMESPACE_ERROR],
2436 AT_DATA([[input.y]],
2437 [[%language "C++"
2438 %header
2439 %define api.namespace {]$1[}
2441 start: %empty;
2444 AT_BISON_CHECK([[input.y]], [1], [],
2445 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
2446 [b4_arg
2447 ])])
2450 AT_CHECK_NAMESPACE_ERROR([[]],
2451                          [[input.y:3.1-24: error: namespace reference is empty]])
2452 AT_CHECK_NAMESPACE_ERROR([[ @tb@@tb@  @tb@ @tb@]],
2453                          [[input.y:3.1-57: error: namespace reference is empty]])
2454 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
2455                          [[input.y:3.1-34: error: namespace reference has consecutive "::"]])
2456 AT_CHECK_NAMESPACE_ERROR([[foo:: @tb@::bar]],
2457                          [[input.y:3.1-38: error: namespace reference has consecutive "::"]])
2458 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
2459                          [[input.y:3.1-31: error: namespace reference has consecutive "::"]])
2460 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
2461                          [[input.y:3.1-32: error: namespace reference has consecutive "::"]])
2462 AT_CHECK_NAMESPACE_ERROR([[foo::bar::@tb@::]],
2463                          [[input.y:3.1-43: error: namespace reference has consecutive "::"]],
2464                          [[input.y:3.1-43: error: namespace reference has a trailing "::"]])
2465 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
2466                          [[input.y:3.1-34: error: namespace reference has a trailing "::"]])
2467 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: @tb@]],
2468                          [[input.y:3.1-41: error: namespace reference has a trailing "::"]])
2469 AT_CHECK_NAMESPACE_ERROR([[::]],
2470                          [[input.y:3.1-26: error: namespace reference has a trailing "::"]])
2472 AT_CLEANUP
2475 ## ------------------------ ##
2476 ## Bad character literals.  ##
2477 ## ------------------------ ##
2479 # Bison used to accept character literals that were empty or contained
2480 # too many characters.
2482 AT_SETUP([[Bad character literals]])
2484 AT_DATA_NO_FINAL_EOL([empty.y],
2485 [[%%
2486 start: '';
2487 start: '
2488 start: ']])
2490 AT_BISON_CHECK([-fcaret empty.y], [1], [],
2491 [[empty.y:2.8-9: error: empty character literal
2492     2 | start: '';
2493       |        ^~
2494 empty.y:3.8-4.0: error: missing "'" at end of line
2495     3 | start: '
2496       |        ^
2497 empty.y:3.8-4.0: error: empty character literal
2498     3 | start: '
2499       |        ^
2500 empty.y:4.8: error: missing "'" at end of file
2501     4 | start: '
2502       |        ^
2503 empty.y:4.8: error: empty character literal
2504     4 | start: '
2505       |        ^
2508 AT_DATA_NO_FINAL_EOL([two.y],
2509 [[%%
2510 start: 'ab';
2511 start: 'ab
2512 start: 'ab]])
2514 AT_BISON_CHECK([two.y], [1], [],
2515 [[two.y:2.8-11: error: extra characters in character literal
2516 two.y:3.8-4.0: error: missing "'" at end of line
2517 two.y:3.8-4.0: error: extra characters in character literal
2518 two.y:4.8-10: error: missing "'" at end of file
2519 two.y:4.8-10: error: extra characters in character literal
2522 AT_DATA_NO_FINAL_EOL([three.y],
2523 [[%%
2524 start: 'abc';
2525 start: 'abc
2526 start: 'abc]])
2528 AT_BISON_CHECK([three.y], [1], [],
2529 [[three.y:2.8-12: error: extra characters in character literal
2530 three.y:3.8-4.0: error: missing "'" at end of line
2531 three.y:3.8-4.0: error: extra characters in character literal
2532 three.y:4.8-11: error: missing "'" at end of file
2533 three.y:4.8-11: error: extra characters in character literal
2536 AT_CLEANUP
2539 ## ------------------------- ##
2540 ## Bad escapes in literals.  ##
2541 ## ------------------------- ##
2543 AT_SETUP([[Bad escapes in literals]])
2545 AT_DATA([input.y],
2546 [[%%
2547 start: '\777' '\0' '\xfff' '\x0'
2548        '\uffff' '\u0000' '\Uffffffff' '\U00000000'
2549        '\ ' '\A';
2552 # It is not easy to create special characters, we cannot even trust tr.
2553 # Beside we cannot even expect "echo '\0'" to output two characters
2554 # (well three with \n): at least Bash 3.2 converts the two-character
2555 # sequence "\0" into a single NUL character.
2556 AT_PERL_REQUIRE([[-e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y]])
2558 AT_BISON_CHECK([input.y], [1], [],
2559 [[input.y:2.9-12: error: invalid number after \-escape: 777
2560 input.y:2.16-17: error: invalid number after \-escape: 0
2561 input.y:2.21-25: error: invalid number after \-escape: xfff
2562 input.y:2.29-31: error: invalid number after \-escape: x0
2563 input.y:3.9-14: error: invalid number after \-escape: uffff
2564 input.y:3.18-23: error: invalid number after \-escape: u0000
2565 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
2566 input.y:3.40-49: error: invalid number after \-escape: U00000000
2567 input.y:4.9-10: error: invalid character after \-escape: ' '
2568 input.y:4.14-15: error: invalid character after \-escape: A
2569 input.y:5.9-16: error: invalid character after \-escape: \t
2570 input.y:5.17: error: invalid character after \-escape: \f
2571 input.y:5.18: error: invalid character after \-escape: \0
2572 input.y:5.19: error: invalid character after \-escape: \001
2575 AT_CLEANUP
2578 ## ------------------------ ##
2579 ## Unexpected end of file.  ##
2580 ## ------------------------ ##
2582 AT_SETUP([[Unexpected end of file]])
2585 AT_DATA([input.y], [])
2586 AT_BISON_CHECK([-fcaret input.y], [1], [],
2587 [[input.y:1.1: error: unexpected end of file
2591 AT_DATA_NO_FINAL_EOL([char.y],
2592 [[%token FOO ']])
2594 AT_BISON_CHECK([-fcaret char.y], [1], [],
2595 [[char.y:1.12: error: missing "'" at end of file
2596     1 | %token FOO '
2597       |            ^
2598 char.y:1.12: error: empty character literal
2599     1 | %token FOO '
2600       |            ^
2604 AT_DATA_NO_FINAL_EOL([escape-in-char.y],
2605 [[%token FOO '\]])
2607 AT_BISON_CHECK([-fcaret escape-in-char.y], [1], [],
2608 [[escape-in-char.y:1.12-13: error: missing '?\'' at end of file
2609     1 | %token FOO '\
2610       |            ^~
2611 escape-in-char.y:1.14: error: unexpected end of file
2612     1 | %token FOO '\
2613       |              ^
2617 AT_DATA_NO_FINAL_EOL([string.y],
2618 [[%token FOO "]])
2620 AT_BISON_CHECK([-fcaret string.y], [1], [],
2621 [[string.y:1.12: error: missing '"' at end of file
2622     1 | %token FOO "
2623       |            ^
2624 string.y:1.13: error: unexpected end of file
2625     1 | %token FOO "
2626       |             ^
2630 AT_DATA_NO_FINAL_EOL([escape-in-string.y],
2631 [[%token FOO "\]])
2633 AT_BISON_CHECK([-fcaret escape-in-string.y], [1], [],
2634 [[escape-in-string.y:1.12-13: error: missing '?"' at end of file
2635     1 | %token FOO "\
2636       |            ^~
2637 escape-in-string.y:1.14: error: unexpected end of file
2638     1 | %token FOO "\
2639       |              ^
2643 AT_DATA_NO_FINAL_EOL([tstring.y],
2644 [[%token FOO _("]])
2646 AT_BISON_CHECK([-fcaret tstring.y], [1], [],
2647 [[tstring.y:1.12-14: error: missing '")' at end of file
2648     1 | %token FOO _("
2649       |            ^~~
2650 tstring.y:1.15: error: unexpected end of file
2651     1 | %token FOO _("
2652       |               ^
2656 AT_DATA_NO_FINAL_EOL([escape-in-tstring.y],
2657 [[%token FOO _("\]])
2659 AT_BISON_CHECK([-fcaret escape-in-tstring.y], [1], [],
2660 [[escape-in-tstring.y:1.12-15: error: missing '?")' at end of file
2661     1 | %token FOO _("\
2662       |            ^~~~
2663 escape-in-tstring.y:1.16: error: unexpected end of file
2664     1 | %token FOO _("\
2665       |                ^
2668 AT_CLEANUP
2671 ## ------------------------- ##
2672 ## LAC: Errors for %define.  ##
2673 ## ------------------------- ##
2675 AT_SETUP([[LAC: Errors for %define]])
2676 AT_KEYWORDS([lac])
2678 AT_DATA([[input.y]],
2679 [[%%
2680 start: %empty;
2683 # Only "full" and "none" are accepted for parse.lac
2684 # Unknown values (such as "unsupported") are rejected
2685 m4_foreach([b4_skel], [[yacc.c], [lalr1.cc], [lalr1.d], [lalr1.java]],
2686 [AT_BISON_CHECK([[-S]b4_skel[ -Dparse.lac=none input.y]])
2687 AT_BISON_CHECK([[-S]b4_skel[ -Dparse.lac=full input.y]])
2688 AT_BISON_CHECK([[-S]b4_skel[ -Dparse.lac=unsupported input.y]],
2689                [[1]], [],
2690 [[<command line>:4: error: invalid value for %define variable 'parse.lac': 'unsupported'
2691 <command line>:4: note: accepted value: 'full'
2692 <command line>:4: note: accepted value: 'none'
2696 # parse.lac.* options are useless if LAC isn't actually activated.
2697 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 -Dparse.lac.memory-trace=full input.y]],
2698                [[1]], [],
2699 [[<command line>:3: error: %define variable 'parse.lac.es-capacity-initial' is not used
2700 <command line>:4: error: %define variable 'parse.lac.memory-trace' is not used
2703 # parse.lac.* options are useless in C++/Java even if LAC is actually activated.
2704 m4_foreach([b4_skel], [[lalr1.cc], [lalr1.java]],
2705 [AT_BISON_CHECK([[-S]b4_skel[ -Dparse.lac=full -Dparse.lac.es-capacity-initial=1 -Dparse.lac.memory-trace=full input.y]],
2706                [[1]], [],
2707 [[<command line>:5: error: %define variable 'parse.lac.es-capacity-initial' is not used
2708 <command line>:6: error: %define variable 'parse.lac.memory-trace' is not used
2712 AT_CLEANUP
2715 ## ---------------------- ##
2716 ## -Werror combinations.  ##
2717 ## ---------------------- ##
2719 AT_SETUP([[-Werror combinations]])
2721 AT_DATA([[input.y]],
2722 [[%%
2723 a: '0' { $$ = $; };
2726 # -Werror is not enabled by -Wall or equivalent.
2727 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
2728 [[input.y:2.15: warning: stray '$' [-Wother]
2730 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
2731 [[input.y:2.15: warning: stray '$' [-Wother]
2733 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
2734 [[input.y:2.15: warning: stray '$' [-Wother]
2737 # -Werror is not disabled by -Wnone or equivalent.
2738 AT_BISON_CHECK([[-Werror,none,other input.y]], [[1]], [[]],
2739 [[input.y:2.15: error: stray '$' [-Werror=other]
2741 AT_BISON_CHECK([[-Werror,no-all,other input.y]], [[1]], [[]],
2742 [[input.y:2.15: error: stray '$' [-Werror=other]
2745 # Check that -Wno-error keeps warnings enabled, but non fatal.
2746 AT_BISON_CHECK([[-Werror -Wno-error=other input.y]], [[0]], [[]],
2747 [[input.y:2.15: warning: stray '$' [-Wother]
2750 AT_BISON_CHECK([[-Wno-error=other -Werror input.y]], [[0]], [[]],
2751 [[input.y:2.15: warning: stray '$' [-Wother]
2754 AT_BISON_CHECK([[-Werror=other -Wno-other input.y]], [[0]], [[]],
2755 [[]])
2757 AT_CLEANUP
2760 ## ------------------------------------------------------ ##
2761 ## %name-prefix and %define api.prefix are incompatible.  ##
2762 ## ------------------------------------------------------ ##
2764 AT_SETUP([[%name-prefix and api.prefix are incompatible]])
2766 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
2767 # --------------------------------------------
2768 m4_pushdef([AT_TEST],
2769 [AT_DATA([[input.y]],
2770 [[$1
2772 exp: %empty;
2774 AT_BISON_CHECK([[$2 -Wno-deprecated input.y]], [[1]], [[]],
2775 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
2779 AT_TEST([%define api.prefix {foo} %name-prefix "bar"], [], [input.y:1.1-24])
2780 AT_TEST([], [-Dapi.prefix={foo} -p bar],                   [<command line>:3])
2781 AT_TEST([%name-prefix "bar"], [-Dapi.prefix={foo}],        [<command line>:3])
2782 AT_TEST([%define api.prefix {foo}], [-p bar],              [input.y:1.1-24])
2784 m4_popdef([AT_TEST])
2786 AT_CLEANUP
2789 ## ----------------------- ##
2790 ## Redefined %union name.  ##
2791 ## ----------------------- ##
2793 AT_SETUP([[Redefined %union name]])
2795 # AT_TEST(DIRECTIVES, EXIT-STATUS, ERROR)
2796 # ---------------------------------------
2797 m4_pushdef([AT_TEST],
2798 [AT_DATA([[input.y]],
2801 exp: %empty;
2804 AT_BISON_CHECK([[input.y]], [$2], [[]],
2805 [$3])
2808 AT_TEST([[%union foo {};
2809 %union {};
2810 %union foo {};
2811 %define api.value.union.name foo]],
2812 [0],
2813 [[input.y:3.8-10: warning: %define variable 'api.value.union.name' redefined [-Wother]
2814 input.y:1.8-10: note: previous definition
2815 input.y:4.1-32: warning: %define variable 'api.value.union.name' redefined [-Wother]
2816 input.y:3.8-10: note: previous definition
2817 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
2820 AT_TEST([[%define api.value.union.name {foo}]], [1],
2821 [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values
2822 input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
2825 AT_TEST([[%define api.value.union.name "foo"]], [1],
2826 [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values
2827 input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
2830 m4_popdef([AT_TEST])
2831 AT_CLEANUP
2836 ## -------------- ##
2837 ## Stray $ or @.  ##
2838 ## -------------- ##
2840 AT_SETUP([[Stray $ or @]])
2841 AT_BISON_OPTION_PUSHDEFS
2843 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
2844 # check that the warnings are reported once, not three times.
2846 AT_DATA_GRAMMAR([[input.y]],
2847 [[%type <TYPE> exp
2848 %token <TYPE> TOK TOK2
2849 %destructor     { $%; @%; } <*> exp TOK;
2850 %initial-action { $%; @%; };
2851 %printer        { $%; @%; } <*> exp TOK;
2852 %{ $ @ %} // Should not warn.
2854 exp: TOK        { $%; @%; $$ = $1; }
2855    | 'a'        { $<->1; $$ = 1; }
2856    | 'b'        { $<foo->bar>$; }
2858 $ @ // Should not warn.
2861 AT_BISON_CHECK([[-Wall input.y]], 0, [],
2862 [[input.y:11.19: warning: stray '$' [-Wother]
2863 input.y:11.23: warning: stray '@' [-Wother]
2864 input.y:12.19: warning: stray '$' [-Wother]
2865 input.y:12.23: warning: stray '@' [-Wother]
2866 input.y:13.19: warning: stray '$' [-Wother]
2867 input.y:13.23: warning: stray '@' [-Wother]
2868 input.y:16.19: warning: stray '$' [-Wother]
2869 input.y:16.23: warning: stray '@' [-Wother]
2870 input.y:17.19: warning: stray '$' [-Wother]
2873 AT_BISON_OPTION_POPDEFS
2874 AT_CLEANUP
2878 ## ---------------- ##
2879 ## Code injection.  ##
2880 ## ---------------- ##
2883 AT_SETUP([[Code injection]])
2885 m4_pattern_allow([^m4_errprintn$])
2887 # AT_TEST([MACRO])
2888 # ----------------
2889 # Try to have MACRO be run by bison.
2890 m4_pushdef([AT_TEST],
2891 [AT_DATA([[input.y]],
2892 [[%type <$1(%type)> exp
2893 %token <$1(%token)> a
2894 %token b
2895 %initial-action
2897   $$;
2898   $<$1(%initial-action)>$
2900 %printer
2902   $$
2903   $<$1(%printer)>$
2904 } <> <*>;
2905 %lex-param
2907   $1(%lex-param)
2909 %parse-param
2911   $1(%parse-param)
2914 exp:
2915   a a[name] b
2916   {
2917     $$;
2918     $][1;
2919     $<$1(action 1)>$
2920     $<$1(action 2)>1
2921     $<$1(action 3)>name
2922     $<$1(action 4)>0
2923     ;
2924   };
2927 # Disable -Wother to avoid the warnings about the suspicious presence
2928 # of `b4_canary` in the output.
2929 AT_FOR_EACH_SKEL(
2930 [AT_BISON_CHECK([[-Wno-other -S ]b4_skel[ ]m4_bmatch(b4_skel, [.*\.\(d\|java\)$], [], [-d])[ input.y]])
2934 AT_TEST([b4_canary])
2935 AT_TEST([@:>@b4_canary])
2937 m4_popdef([AT_TEST])
2939 AT_CLEANUP
2942 ##----------------------- ##
2943 ## Deprecated directives. ##
2944 ## ---------------------- ##
2946 AT_SETUP([[Deprecated directives]])
2948 AT_KEYWORDS([[deprec]])
2950 AT_BISON_OPTION_PUSHDEFS
2951 AT_DATA_GRAMMAR([[input.y]],
2953 %default_prec
2954 %error_verbose
2955 %expect_rr 0
2956 %file-prefix = "foo"
2957 %file-prefix
2959 "bar"
2960         %fixed-output_files
2961         %fixed_output-files
2962 %fixed-output-files
2963 %name-prefix= "foo"
2964 %no-default_prec
2965 %no_default-prec
2966 %no_lines
2967 %output = "output.c"
2968 %pure_parser
2969 %token_table
2970 %error-verbose
2971 %glr-parser
2972 %name-prefix "bar"
2973 %defines "header.h"
2975 exp : '0'
2978 AT_DATA([errors-all],
2979 [[input.y:10.1-13: warning: deprecated directive: '%default_prec', use '%default-prec' [-Wdeprecated]
2980 fix-it:"input.y":{10:1-10:14}:"%default-prec"
2981 input.y:11.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
2982 fix-it:"input.y":{11:1-11:15}:"%define parse.error verbose"
2983 input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2984 fix-it:"input.y":{12:1-12:11}:"%expect-rr"
2985 input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
2986 fix-it:"input.y":{13:1-13:15}:"%file-prefix"
2987 input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
2988 input.y:13.1-20: note: previous declaration
2989 fix-it:"input.y":{14:1-16:6}:""
2990 input.y:17.9-27: warning: deprecated directive: '%fixed-output_files', use '%output "y.tab.c"' [-Wdeprecated]
2991 fix-it:"input.y":{17:2-17:21}:"%output \"y.tab.c\""
2992 input.y:18.9-27: warning: deprecated directive: '%fixed_output-files', use '%output "y.tab.c"' [-Wdeprecated]
2993 fix-it:"input.y":{18:9-18:28}:"%output \"y.tab.c\""
2994 input.y:19.1-19: warning: deprecated directive: '%fixed-output-files', use '%output "y.tab.c"' [-Wdeprecated]
2995 fix-it:"input.y":{19:1-19:20}:"%output \"y.tab.c\""
2996 input.y:20.1-19: warning: deprecated directive: '%name-prefix= "foo"', use '%define api.prefix {foo}' [-Wdeprecated]
2997 fix-it:"input.y":{20:1-20:20}:"%define api.prefix {foo}"
2998 input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated]
2999 fix-it:"input.y":{21:1-21:17}:"%no-default-prec"
3000 input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated]
3001 fix-it:"input.y":{22:1-22:17}:"%no-default-prec"
3002 input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated]
3003 fix-it:"input.y":{23:1-23:10}:"%no-lines"
3004 input.y:24.1-9: warning: deprecated directive: '%output =', use '%output' [-Wdeprecated]
3005 fix-it:"input.y":{24:1-24:10}:"%output"
3006 input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%define api.pure' [-Wdeprecated]
3007 fix-it:"input.y":{25:1-25:13}:"%define api.pure"
3008 input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
3009 fix-it:"input.y":{26:1-26:13}:"%token-table"
3010 input.y:27.1-14: warning: %define variable 'parse.error' redefined [-Wother]
3011 input.y:11.1-14: note: previous definition
3012 fix-it:"input.y":{27:1-27:15}:""
3013 input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother]
3014 input.y:13.1-20: note: previous declaration
3015 fix-it:"input.y":{29:1-29:19}:""
3016 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
3019 AT_CHECK([cp errors-all experr])
3020 AT_BISON_CHECK([[-ffixit input.y]], [], [], [experr])
3022 AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
3023 AT_BISON_CHECK([[input.y]], [], [], [experr])
3026 # Update the input file.  Make sure we generated nothing.
3027 AT_CHECK([rm -f output.c])
3028 AT_CHECK([cp input.y input.y.orig])
3029 AT_CHECK([sed -e '/fix-it/d' <errors-all >experr])
3030 AT_CHECK([echo "bison: file 'input.y' was updated (backup: 'input.y~')" >>experr])
3031 AT_BISON_CHECK([[--update input.y]], [], [[]], [experr])
3033 # Check the backup.
3034 AT_CHECK([diff input.y.orig input.y~])
3036 # Check we did not generate any file.
3037 AT_CHECK([test ! -f output.c])
3039 # Check the update.
3040 AT_CHECK([sed -e '1,8d' input.y], [],
3042 %default-prec
3043 %define parse.error verbose
3044 %expect-rr 0
3045 %file-prefix "foo"
3046         %output "y.tab.c"
3047         %output "y.tab.c"
3048 %output "y.tab.c"
3049 %define api.prefix {foo}
3050 %no-default-prec
3051 %no-default-prec
3052 %no-lines
3053 %output "output.c"
3054 %define api.pure
3055 %token-table
3056 %glr-parser
3057 %defines "header.h"
3059 exp : '0'
3062 AT_BISON_CHECK([[input.y]])
3064 AT_BISON_OPTION_POPDEFS
3065 AT_CLEANUP
3068 ## ---------------------------- ##
3069 ## Unput's effect on locations. ##
3070 ## ---------------------------- ##
3072 # When the scanner detects a deprecated construct, it unputs the
3073 # correct version, but it should *not* have any impact on the scanner
3074 # cursor. If it does, the locations of directives on the same line
3075 # become erroneous.
3077 AT_SETUP([[Unput's effect on locations]])
3079 AT_KEYWORDS([[deprec]])
3081 AT_BISON_OPTION_PUSHDEFS
3082 AT_DATA_GRAMMAR([[input.y]],
3084 %glr-parser
3085 %expect_rr 42 %expect_rr 42
3086               %expect_rr 42
3087 %error_verbose %error_verbose
3088                %error_verbose
3089 %% exp: '0'
3092 AT_BISON_CHECK([[input.y]], [[1]], [[]],
3093 [[input.y:11.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
3094 input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
3095 input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
3096 input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
3097 input.y:13.16-29: warning: %define variable 'parse.error' redefined [-Wother]
3098 input.y:13.1-14: note: previous definition
3099 input.y:14.16-29: warning: %define variable 'parse.error' redefined [-Wother]
3100 input.y:13.16-29: note: previous definition
3101 input.y: error: reduce/reduce conflicts: 0 found, 42 expected
3102 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
3105 AT_BISON_OPTION_POPDEFS
3106 AT_CLEANUP
3109 ## -------------------------- ##
3110 ## Non-deprecated directives. ##
3111 ## -------------------------- ##
3113 AT_SETUP([[Non-deprecated directives]])
3115 AT_KEYWORDS([[deprec]])
3117 AT_BISON_OPTION_PUSHDEFS
3118 AT_DATA_GRAMMAR([[input.y]],
3120 %default-prec
3121 %define parse.error verbose
3122 %expect-rr 42
3123 %file-prefix "foo"
3124 %file-prefix
3125 "bar"
3126 %no-default-prec
3127 %no-lines
3128 %output "foo"
3129 %token-table
3130 %% exp : '0'
3133 AT_BISON_CHECK([[input.y]], [[0]], [[]],
3134 [[input.y:14.1-15.5: warning: duplicate directive: '%file-prefix' [-Wother]
3135 input.y:13.1-18: note: previous declaration
3136 input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
3137 input.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
3140 AT_BISON_OPTION_POPDEFS
3141 AT_CLEANUP
3144 ## -------------------- ##
3145 ## Cannot type action.  ##
3146 ## -------------------- ##
3148 AT_SETUP([[Cannot type action]])
3150 AT_BISON_OPTION_PUSHDEFS
3151 AT_DATA_GRAMMAR([[input.y]],
3152 [[%%
3153 exp: <int> {}
3156 AT_BISON_CHECK([[-fcaret input.y]], [[0]], [[]],
3157 [[input.y:10.6-13: warning: only midrule actions can be typed: int [-Wother]
3158    10 | exp: <int> {}
3159       |      ^~~~~~~~
3162 AT_BISON_OPTION_POPDEFS
3163 AT_CLEANUP
3167 ## -------------------------------------- ##
3168 ## Character literals and api.token.raw.  ##
3169 ## -------------------------------------- ##
3171 AT_SETUP([[Character literals and api.token.raw]])
3173 AT_BISON_OPTION_PUSHDEFS
3174 AT_DATA_GRAMMAR([[input.y]],
3175 [[%define api.token.raw
3176 %token 'a'
3178 exp: 'b' "c" {}
3181 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
3182 [[input.y:10.8-10: error: character literals cannot be used together with api.token.raw
3183    10 | %token 'a'
3184       |        ^~~
3185 input.y:9.1-21: note: definition of api.token.raw
3186     9 | %define api.token.raw
3187       | ^~~~~~~~~~~~~~~~~~~~~
3188 input.y:12.6-8: error: character literals cannot be used together with api.token.raw
3189    12 | exp: 'b' "c" {}
3190       |      ^~~
3191 input.y:9.1-21: note: definition of api.token.raw
3192     9 | %define api.token.raw
3193       | ^~~~~~~~~~~~~~~~~~~~~
3196 AT_BISON_OPTION_POPDEFS
3197 AT_CLEANUP
3201 ## ------------------------------ ##
3202 ## %token-table and parse.error.  ##
3203 ## ------------------------------ ##
3205 AT_SETUP([[%token-table and parse.error]])
3207 # AT_TEST(DIRECTIVES, ERROR-LOCATION)
3208 # -----------------------------------
3209 m4_pushdef([AT_TEST],
3210 [AT_DATA([[input.y]],
3211 [[$1
3213 exp: %empty;
3215 AT_BISON_CHECK([[input.y]], [[1]], [[]],
3216 [$2: error: '%token-table' and '%define parse.error (custom|detailed)' cannot be used together
3220 AT_TEST([%define parse.error custom %token-table],  [[input.y:1.1-26]])
3221 AT_TEST([%define parse.error detailed %token-table],[[input.y:1.1-28]])
3223 m4_popdef([AT_TEST])
3225 AT_CLEANUP
3227 ## --------------------------------------- ##
3228 ## Invalid file prefix mapping arguments.  ##
3229 ## --------------------------------------- ##
3231 AT_SETUP([[Invalid file prefix mapping arguments]])
3233 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
3234 # --------------------------------------------
3235 m4_pushdef([AT_TEST],
3236 [AT_DATA([[input.y]],
3239 exp: %empty;
3241 AT_BISON_CHECK([[$1 input.y]], [[1]], [[]],
3242 [[$3: error: invalid argument for '--file-prefix-map': $2
3246 AT_TEST([-M foo], [foo], [<command line>:4])
3247 AT_TEST([--file-prefix-map foo], [foo], [<command line>:4])
3248 AT_TEST([-M foo=bar -M baz], [baz], [<command line>:6])
3249 AT_TEST([-M foo= -M baz], [baz], [<command line>:6])
3251 m4_popdef([AT_TEST])
3253 AT_CLEANUP