From 10591c887977534cd22f3693cc7f721e42a76287 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 24 Dec 2018 08:19:01 +0100 Subject: [PATCH] c++: also provide a copy constructor for symbol_type Suggested by Wolfgang Thaller. http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00081.html * data/c++.m4 (basic_symbol, by_type): Instead of provide either move or copy constructor, always provide the copy one. * tests/c++.at (C++ Variant-based Symbols Unit Tests): Check it. --- NEWS | 8 ++++++++ data/c++.m4 | 44 +++++++++++++++++++++++++++++++++----------- tests/c++.at | 8 ++++++++ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index c67fb142..0db77cc7 100644 --- a/NEWS +++ b/NEWS @@ -210,6 +210,14 @@ GNU Bison NEWS literal such as ‘"number"’. The postfix quantifiers are ‘?’ (zero or one), ‘*’ (zero or more) and ‘+’ (one or more). +* Noteworthy changes in release 3.2.4 (2018-12-24) [stable] + +** Bug fixes + + Fix the move constructor of symbol_type. + + Always provide a copy constructor for symbol_type, even in modern C++. + * Noteworthy changes in release 3.2.3 (2018-12-18) [stable] ** Bug fixes diff --git a/data/c++.m4 b/data/c++.m4 index 3dea30a4..dbf0647a 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -258,8 +258,13 @@ m4_define([b4_symbol_type_declare], /// Default constructor. basic_symbol (); - /// Move or copy constructor. - basic_symbol (YY_RVREF (basic_symbol) that);]b4_variant_if([[ +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + basic_symbol (basic_symbol&& that); +#endif + + /// Copy constructor. + basic_symbol (const basic_symbol& that);]b4_variant_if([[ /// Constructor for valueless symbols, and symbols from each type. ]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[ @@ -303,8 +308,13 @@ m4_define([b4_symbol_type_declare], /// Default constructor. by_type (); - /// Move or copy constructor. - by_type (YY_RVREF (by_type) that); +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + by_type (by_type&& that); +#endif + + /// Copy constructor. + by_type (const by_type& that); /// The symbol type as needed by the constructor. typedef token_type kind_type; @@ -362,13 +372,25 @@ m4_define([b4_public_types_define], , location ()])[ {} +#if 201103L <= YY_CPLUSPLUS template - ]b4_parser_class_name[::basic_symbol::basic_symbol (YY_RVREF (basic_symbol) that) - : Base (YY_MOVE (that)) - , value (]b4_variant_if([], [YY_MOVE (that.value)]))b4_locations_if([ - , location (YY_MOVE (that.location))])[ + ]b4_parser_class_name[::basic_symbol::basic_symbol (basic_symbol&& that) + : Base (std::move (that)) + , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([ + , location (std::move (that.location))])[ {]b4_variant_if([ - b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY], + b4_symbol_variant([this->type_get ()], [value], [move], + [std::move (that.value)]) + ])[} +#endif + + template + ]b4_parser_class_name[::basic_symbol::basic_symbol (const basic_symbol& that) + : Base (that) + , value (]b4_variant_if([], [that.value]))b4_locations_if([ + , location (that.location)])[ + {]b4_variant_if([ + b4_symbol_variant([this->type_get ()], [value], [copy], [YY_MOVE (that.value)]) ])[} @@ -452,11 +474,11 @@ m4_define([b4_public_types_define], { that.clear (); } -#else +#endif + ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& that) : type (that.type) {} -#endif ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (token_type t) : type (yytranslate_ (t)) diff --git a/tests/c++.at b/tests/c++.at index 8be85b8a..92697379 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -171,6 +171,14 @@ int main() } #endif + // symbol_type: copy constructor. + { + parser::symbol_type s = parser::make_INT (51); + parser::symbol_type s2 = s; + assert_eq (s.value.as (), 51); + assert_eq (s2.value.as (), 51); + } + // stack_symbol_type: construction, accessor. { #if 201103L <= YY_CPLUSPLUS