93e840
commit 952416114729b95209dccfc4edacfc1ff13b4e82
93e840
Author: Akim Demaille <akim@lrde.epita.fr>
93e840
Date:   Mon Jan 26 18:23:12 2015 +0100
93e840
93e840
    tests: c++: fix symbol lookup issue
93e840
    
93e840
    Sun C 5.13 SunOS_sparc 2014/10/20 reports errors on tests 430-432.
93e840
    
93e840
    Reported by Dennis Clarke.
93e840
    <http://lists.gnu.org/archive/html/bug-bison/2015-01/msg00087.html>
93e840
    
93e840
    * tests/c++.at (Variants): Be sure to emit operator<< before using it:
93e840
    use "%code top" rather than "%code".
93e840
    Prefer std::vector to std::list.
93e840
    Do not define anything in std::, to avoid undefined behavior.
93e840
93e840
diff --git a/tests/c++.at b/tests/c++.at
93e840
index 55d7d40..60292f4 100644
93e840
--- a/tests/c++.at
93e840
+++ b/tests/c++.at
93e840
@@ -96,7 +96,7 @@ AT_SETUP([C++ Variant-based Symbols])
93e840
 AT_KEYWORDS([variant])
93e840
 
93e840
 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %debug $1])
93e840
-# Store strings and integers in a list of strings.
93e840
+# Store strings and integers in a vector of strings.
93e840
 AT_DATA_GRAMMAR([list.y],
93e840
 [[%skeleton "lalr1.cc"
93e840
 %define api.value.type variant
93e840
@@ -114,20 +114,20 @@ AT_DATA_GRAMMAR([list.y],
93e840
 }
93e840
 
93e840
 %token <int> INT "int"
93e840
-%type < std::list<int> > exp
93e840
+%type < std::vector<int> > exp
93e840
 
93e840
 %printer { yyo << $$; } <int>
93e840
 %printer
93e840
   {
93e840
-    for (std::list<int>::const_iterator i = $$.begin (); i != $$.end (); ++i)
93e840
+    for (std::vector<int>::const_iterator i = $$.begin (); i != $$.end (); ++i)
93e840
       {
93e840
         if (i != $$.begin ())
93e840
           yyo << ", ";
93e840
         yyo << *i;
93e840
       }
93e840
-  } < std::list<int> >
93e840
+  } < std::vector<int> >
93e840
 
93e840
-%code requires { #include <list> }
93e840
+%code requires { #include <vector> }
93e840
 %code { int yylex (yy::parser::semantic_type* yylval); }
93e840
 
93e840
 %%
93e840
@@ -185,7 +185,7 @@ m4_pushdef([AT_TEST],
93e840
 [AT_SETUP([Variants $1])
93e840
 
93e840
 AT_BISON_OPTION_PUSHDEFS([%debug $1])
93e840
-# Store strings and integers in a list of strings.
93e840
+# Store strings and integers in a vector of strings.
93e840
 AT_DATA_GRAMMAR([list.y],
93e840
 [[%debug
93e840
 %define api.value.type variant
93e840
@@ -194,29 +194,25 @@ AT_DATA_GRAMMAR([list.y],
93e840
 
93e840
 %code requires // code for the .hh file
93e840
 {
93e840
-#include <list>
93e840
+#include <vector>
93e840
 #include <string>
93e840
-typedef std::list<std::string> strings_type;
93e840
+typedef std::vector<std::string> strings_type;
93e840
 }
93e840
 
93e840
-%code // code for the .cc file
93e840
+%code top // code for the .cc file.
93e840
 {
93e840
 #include <cstdlib> // abort, getenv
93e840
 #include <iostream>
93e840
+#include <vector>
93e840
 #include <sstream>
93e840
+#include <string>
93e840
 
93e840
-  namespace yy
93e840
-  {
93e840
-    static]AT_TOKEN_CTOR_IF([[
93e840
-    parser::symbol_type yylex ()]], [[
93e840
-    parser::token_type yylex (parser::semantic_type* yylval]AT_LOCATION_IF([,
93e840
-                              parser::location_type* yylloc])[)]])[;
93e840
-  }
93e840
 
93e840
-  // Printing a list of strings (for %printer).
93e840
-  // Koening look up will look into std, since that's an std::list.
93e840
-  namespace std
93e840
+  typedef std::vector<std::string> strings_type;
93e840
+
93e840
+  namespace yy
93e840
   {
93e840
+    // Must be available early, as is used in %destructor.
93e840
     std::ostream&
93e840
     operator<<(std::ostream& o, const strings_type& s)
93e840
     {
93e840
@@ -230,16 +226,27 @@ typedef std::list<std::string> strings_type;
93e840
       return o << ')';
93e840
     }
93e840
   }
93e840
+}
93e840
 
93e840
-  // Conversion to string.
93e840
-  template <typename T>
93e840
-    inline
93e840
-    std::string
93e840
-    to_string (const T& t)
93e840
+%code // code for the .cc file.
93e840
+{
93e840
+  namespace yy
93e840
   {
93e840
-    std::ostringstream o;
93e840
-    o << t;
93e840
-    return o.str ();
93e840
+    static]AT_TOKEN_CTOR_IF([[
93e840
+    parser::symbol_type yylex ()]], [[
93e840
+    parser::token_type yylex (parser::semantic_type* yylval]AT_LOCATION_IF([,
93e840
+                              parser::location_type* yylloc])[)]])[;
93e840
+
93e840
+    // Conversion to string.
93e840
+    template <typename T>
93e840
+      inline
93e840
+      std::string
93e840
+      to_string (const T& t)
93e840
+    {
93e840
+      std::ostringstream o;
93e840
+      o << t;
93e840
+      return o.str ();
93e840
+    }
93e840
   }
93e840
 }
93e840
 
93e840
@@ -252,10 +259,10 @@ typedef std::list<std::string> strings_type;
93e840
 // Using the template type to exercize its parsing.
93e840
 // Starting with :: to ensure we don't output "<::" which starts by the
93e840
 // digraph for the left square bracket.
93e840
-%type <::std::list<std::string>> list;
93e840
+%type <::std::vector<std::string>> list;
93e840
 
93e840
 %printer { yyo << $$; }
93e840
-  <int> <::std::string> <::std::list<std::string>>;
93e840
+  <int> <::std::string> <::std::vector<std::string>>;
93e840
 %destructor { std::cerr << "Destroy: " << $$ << '\n'; } <*>;
93e840
 %destructor { std::cerr << "Destroy: \"" << $$ << "\"\n"; } <::std::string>;
93e840
 %%