]> git.saurik.com Git - bison.git/commitdiff
c++: fix the use of destructors when variants are enabled
authorAkim Demaille <akim@lrde.epita.fr>
Fri, 9 Jan 2015 11:01:22 +0000 (12:01 +0100)
committerAkim Demaille <akim@lrde.epita.fr>
Fri, 9 Jan 2015 12:54:58 +0000 (13:54 +0100)
When using variants, destructors generate invalid code.
<http://lists.gnu.org/archive/html/bug-bison/2014-09/msg00005.html>
Reported by Michael Catanzaro.

* data/c++.m4 (~basic_symbol): b4_symbol_foreach works on yysym:
define it.
* tests/c++.at (Variants): Check it.

NEWS
THANKS
data/c++.m4
tests/c++.at

diff --git a/NEWS b/NEWS
index 490e89ed5c9cbe1ae340d45b924c62da22c587a8..18771946493ee66703770dfc06b5e8daec59a5ff 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,19 +4,23 @@ GNU Bison NEWS
 
 ** Bug fixes
 
 
 ** Bug fixes
 
-*** Named %union support
+*** C++ with Variants (lalr1.cc)
+
+  Problems with %destructor and '%define parse.assert' have been fixed.
+
+*** Named %union support (yacc.c, glr.c)
 
   Bison 3.0 introduced a regression on named %union such as
 
     %union foo { int ival; };
 
 
   Bison 3.0 introduced a regression on named %union such as
 
     %union foo { int ival; };
 
-  The possibility to use a name was introduced ``for Yacc compatibility''.
+  The possibility to use a name was introduced "for Yacc compatibility".
   It is however not required by POSIX Yacc, and its usefulness is not clear.
 
   It is however not required by POSIX Yacc, and its usefulness is not clear.
 
-*** %define api.value.type union with %defines
+*** %define api.value.type union with %defines (yacc.c, glr.c)
 
 
-  The yacc.c and glr.c parsers were broken when %defines was used
-  together with "%define api.value.type union".
+  The C parsers were broken when %defines was used together with "%define
+  api.value.type union".
 
 *** Redeclarations are reported in proper order
 
 
 *** Redeclarations are reported in proper order
 
diff --git a/THANKS b/THANKS
index 98ec269d703d25fe516b5357ca42cf07b0a09458..d5feb16e33623d01c8f084bcf69fc466220be285 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -83,6 +83,7 @@ Martin Mokrejs            mmokrejs@natur.cuni.cz
 Martin Nylin              martin.nylin@linuxmail.org
 Matt Kraai                kraai@alumni.cmu.edu
 Matt Rosing               rosing@peakfive.com
 Martin Nylin              martin.nylin@linuxmail.org
 Matt Kraai                kraai@alumni.cmu.edu
 Matt Rosing               rosing@peakfive.com
+Michael Catanzaro         mcatanzaro@gnome.org
 Michael Felt              mamfelt@gmail.com
 Michael Hayes             m.hayes@elec.canterbury.ac.nz
 Michael Raskin            7c6f434c@mail.ru
 Michael Felt              mamfelt@gmail.com
 Michael Hayes             m.hayes@elec.canterbury.ac.nz
 Michael Raskin            7c6f434c@mail.ru
index 8494d2142cb7f56f5f7f599f90e3f2c67cbb6b9f..4321c3056e1e3be6c80bd3b0933dd6d243b86d46 100644 (file)
@@ -346,6 +346,7 @@ m4_define([b4_public_types_define],
   {]b4_variant_if([[
     // User destructor.
     symbol_number_type yytype = this->type_get ();
   {]b4_variant_if([[
     // User destructor.
     symbol_number_type yytype = this->type_get ();
+    basic_symbol<Base>& yysym = *this;
     switch (yytype)
     {
 ]b4_symbol_foreach([b4_symbol_destructor])dnl
     switch (yytype)
     {
 ]b4_symbol_foreach([b4_symbol_destructor])dnl
index e6d6983116954483a06adbfa036544588fd18c89..737037d32c2821b099f0675b4779483e0b3375ca 100644 (file)
@@ -252,10 +252,12 @@ typedef std::list<std::string> strings_type;
 // Using the template type to exercize its parsing.
 // Starting with :: to ensure we don't output "<::" which starts by the
 // digraph for the left square bracket.
 // Using the template type to exercize its parsing.
 // Starting with :: to ensure we don't output "<::" which starts by the
 // digraph for the left square bracket.
-%type <::std::list<std::string>> list result;
+%type <::std::list<std::string>> list;
 
 %printer { yyo << $$; }
   <int> <::std::string> <::std::list<std::string>>;
 
 %printer { yyo << $$; }
   <int> <::std::string> <::std::list<std::string>>;
+%destructor { std::cerr << "Destroy: " << $$ << '\n'; } <*>;
+%destructor { std::cerr << "Destroy: \"" << $$ << "\"\n"; } <::std::string>;
 %%
 
 result:
 %%
 
 result:
@@ -336,8 +338,31 @@ namespace yy
 
 AT_FULL_COMPILE([list])
 AT_PARSER_CHECK([./list], 0,
 
 AT_FULL_COMPILE([list])
 AT_PARSER_CHECK([./list], 0,
-[(0, 1, 2, 4, 6)
-])
+[[(0, 1, 2, 4, 6)
+]],
+[[Destroy: ""
+Destroy: "0"
+Destroy: (0)
+Destroy: 1
+Destroy: "1"
+Destroy: ()
+Destroy: ""
+Destroy: "2"
+Destroy: ()
+Destroy: ""
+Destroy: 3
+Destroy: ()
+Destroy: ""
+Destroy: "4"
+Destroy: ()
+Destroy: ()
+Destroy: 5
+Destroy: ()
+Destroy: ""
+Destroy: "6"
+Destroy: ()
+Destroy: (0, 1, 2, 4, 6)
+]])
 
 AT_BISON_OPTION_POPDEFS
 AT_CLEANUP
 
 AT_BISON_OPTION_POPDEFS
 AT_CLEANUP
@@ -826,10 +851,10 @@ list:
 
 item:
   'a'     { $$ = $][1; }
 
 item:
   'a'     { $$ = $][1; }
-| 'e'     { YYUSE ($$); YYUSE($][1); error ("syntax error"); }
+| 'e'     { YYUSE ($$); YYUSE ($][1); error ("syntax error"); }
 // Not just 'E', otherwise we reduce when 'E' is the lookahead, and
 // then the stack is emptied, defeating the point of the test.
 // Not just 'E', otherwise we reduce when 'E' is the lookahead, and
 // then the stack is emptied, defeating the point of the test.
-| 'E' 'a' { YYUSE($][1); $$ = $][2; }
+| 'E' 'a' { YYUSE ($][1); $$ = $][2; }
 | 'R'     { ]AT_VARIANT_IF([], [$$ = YY_NULLPTR; delete $][1]; )[YYERROR; }
 | 'p'     { $$ = $][1; }
 | 's'     { $$ = $][1; throw std::runtime_error ("reduction"); }
 | 'R'     { ]AT_VARIANT_IF([], [$$ = YY_NULLPTR; delete $][1]; )[YYERROR; }
 | 'p'     { $$ = $][1; }
 | 's'     { $$ = $][1; throw std::runtime_error ("reduction"); }