bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/5] tests: prepare a test for automove


From: Akim Demaille
Subject: [PATCH 1/5] tests: prepare a test for automove
Date: Sat, 22 Sep 2018 12:53:20 +0200

The 'Variants' tests are well suited to check support for move, and in
particular for the forthcoming automove feature.  But the tests were
written to show the best practice in C++98, using swap:

    list "," item { std::swap ($$, $1); $$.push_back ($3); }

This cannot work with std::move.  So, make this example simpler, based
on regular assignment instead of swap, which is a regression for
C++98 (as the new traces show), but will be an improvement for modern
C++ with automove.

* tests/c++.at (Variants): Stop using swap.
We don't generate a header file, so remove the 'require' code section.
Adjust expectations.
---
 tests/c++.at | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/tests/c++.at b/tests/c++.at
index c89b6e25..2193f88f 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -214,13 +214,6 @@ AT_DATA_GRAMMAR([list.y],
 ]m4_bpatsubst([$1], [\\n], [
 ])[
 
-%code requires // code for the .hh file
-{
-#include <vector>
-#include <string>
-typedef std::vector<std::string> strings_type;
-}
-
 %code top // code for the .cc file.
 {
 #include <cstdlib> // abort, getenv
@@ -295,12 +288,12 @@ result:
 
 list:
   item          { $$.push_back ($][1); }
-| list "," item { std::swap ($$, $][1); $$.push_back ($][3); }
-| list error    { std::swap ($$, $][1); }
+| list "," item { $$ = $][1; $$.push_back ($][3); }
+| list error    { $$ = $][1; }
 ;
 
 item:
-  TEXT          { std::swap ($$, $][1); }
+  TEXT          { $$ = $][1; }
 | NUMBER        { if ($][1 == 3) YYERROR; else $$ = to_string ($][1); }
 ;
 %%
@@ -369,26 +362,26 @@ AT_FULL_COMPILE([list])
 AT_PARSER_CHECK([./list], 0,
 [[(0, 1, 2, 4, 6)
 ]],
-[[Destroy: ""
+[[Destroy: "0"
 Destroy: "0"
 Destroy: 1
 Destroy: "1"
-Destroy: ()
-Destroy: ""
+Destroy: (0)
 Destroy: "2"
-Destroy: ()
+Destroy: "2"
+Destroy: (0, 1)
 Destroy: ""
 Destroy: 3
-Destroy: ()
-Destroy: ""
+Destroy: (0, 1, 2)
+Destroy: "4"
 Destroy: "4"
-Destroy: ()
-Destroy: ()
+Destroy: (0, 1, 2)
+Destroy: (0, 1, 2, 4)
 Destroy: 5
-Destroy: ()
-Destroy: ""
+Destroy: (0, 1, 2, 4)
+Destroy: "6"
 Destroy: "6"
-Destroy: ()
+Destroy: (0, 1, 2, 4)
 Destroy: (0, 1, 2, 4, 6)
 ]])
 ])
-- 
2.19.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]