[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/5] news: c++: move semantics
From: |
Akim Demaille |
Subject: |
[PATCH 5/5] news: c++: move semantics |
Date: |
Sat, 22 Sep 2018 12:53:24 +0200 |
---
NEWS | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
doc/bison.texi | 3 ---
2 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index 47aa9cf1..b5d59626 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,58 @@ GNU Bison NEWS
* Noteworthy changes in release ?.? (????-??-??) [?]
+** New features
+
+*** C++: Support for move semantics (lalr1.cc)
+
+ The lalr1.cc skeleton now fully supports C++ move semantics, while
+ maintaining compatibility with C++98. You may now store move-only types
+ when using Bison's variants to store semantic values. For instance:
+
+ %code {
+ #include <memory>
+ #include <vector>
+ }
+
+ %skeleton "lalr1.cc"
+ %define api.value.type variant
+
+ %%
+
+ %token <int> INT "int";
+ %nterm <std::unique_ptr<int>> int;
+ %nterm <std::vector<std::unique_ptr<int>>> list;
+
+ list:
+ %empty {}
+ | list int { $$ = std::move($1); $$.emplace_back(std::move($2)); }
+
+ int: "int" { $$ = std::make_unique<int>($1); }
+
+*** C++: Implicit move of right-hand side values (lalr1.cc)
+
+ In modern C++ (C++11 and later), you should always use 'std::move' with
+ the values of the right-hand side symbols ($1, $2, etc.). It is mandatory
+ for move-only types such as unique_ptr, and provides a significant speedup
+ for large types such as std::string, or std::vector, etc.
+
+ If '%define api.value.automove' is set, every occurrence '$n' is replaced
+ by 'std::move ($n)'. The second rule in the previous grammar can be
+ simplified to:
+
+ list: list int { $$ = $1; $$.emplace_back($2); }
+
+ A warning is issued when automove is enabled, and a value is used several
+ times.
+
+ input.yy:16.31-32: warning: multiple occurrences of $2 with
api.value.automove enabled [-Wother]
+ exp: "twice" exp { $$ = $2 + $2; }
+ ^^
+
+ Enabling api.value.automove does not require support for modern C++. The
+ generated code is valid C++98/03, but will use copies instead of moves.
+
+ The new examples/variant-11.yy shows these features in action.
* Noteworthy changes in release 3.1 (2018-08-27) [stable]
diff --git a/doc/bison.texi b/doc/bison.texi
index 3620c60f..3726854c 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -10705,9 +10705,6 @@ therefore, since, as far as we know, @code{double} is
the most demanding
type on all platforms, alignments are enforced for @code{double} whatever
types are actually used. This may waste space in some cases.
address@hidden
-Move semantics is not yet supported, but will soon be added.
-
@item
There might be portability issues we are not aware of.
@end itemize
--
2.19.0
- RFC: api.value.automove, Akim Demaille, 2018/09/19
- Re: RFC: api.value.automove, Hans Ã…berg, 2018/09/19
- Re: RFC: api.value.automove, Frank Heckenbach, 2018/09/20
- Re: RFC: api.value.automove, Akim Demaille, 2018/09/21
- Re: RFC: api.value.automove, Frank Heckenbach, 2018/09/21
- [PATCH 0/5] lalr1.cc: automove, Akim Demaille, 2018/09/22
- [PATCH 1/5] tests: prepare a test for automove, Akim Demaille, 2018/09/22
- [PATCH 2/5] tests: c++: use a custom string type, Akim Demaille, 2018/09/22
- [PATCH 3/5] c++: introduce api.value.automove, Akim Demaille, 2018/09/22
- [PATCH 4/5] c++: issue a warning with a value is moved several times, Akim Demaille, 2018/09/22
- [PATCH 5/5] news: c++: move semantics,
Akim Demaille <=