+
+
+## ------------------------------------------------------------------------- ##
+## Duplicated user destructor for lookahead ##
+## Thanks to Joel E. Denny for this test; see ##
+## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00035.html>. ##
+## ------------------------------------------------------------------------- ##
+
+AT_SETUP([Duplicated user destructor for lookahead])
+
+AT_DATA_GRAMMAR([glr-regr7.y],
+[[
+%{
+ #include <stdio.h>
+ #include <stdlib.h>
+ static void yyerror (char const *);
+ static int yylex (void);
+ #define YYSTACKEXPANDABLE 0
+%}
+
+%glr-parser
+%union { int *count; }
+%type <count> 'a'
+
+%destructor {
+ if ((*$$)++)
+ fprintf (stderr, "Destructor called on same value twice.\n");
+} 'a'
+
+%%
+
+start:
+ stack1 start
+ | stack2 start
+ | /* empty */
+ ;
+stack1: 'a' ;
+stack2: 'a' ;
+
+%%
+
+static int
+yylex (void)
+{
+ yylval.count = malloc (sizeof (int));
+ if (!yylval.count)
+ {
+ fprintf (stderr, "Test inconclusive.\n");
+ exit (EXIT_FAILURE);
+ }
+ *yylval.count = 0;
+ return 'a';
+}
+
+static void
+yyerror (char const *msg)
+{
+ fprintf (stderr, "%s\n", msg);
+}
+
+int
+main (void)
+{
+ return yyparse ();
+}
+]])
+
+AT_CHECK([[bison -o glr-regr7.c glr-regr7.y]], 0, [],
+[glr-regr7.y: conflicts: 2 reduce/reduce
+])
+AT_COMPILE([glr-regr7])
+
+AT_CHECK([[exit 77; ./glr-regr7]], 2, [],
+[memory exhausted
+])
+
+AT_CLEANUP