mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
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.
This commit is contained in:
5
NEWS
5
NEWS
@@ -2,6 +2,11 @@ GNU Bison NEWS
|
|||||||
|
|
||||||
* Noteworthy changes in release ?.? (????-??-??) [?]
|
* Noteworthy changes in release ?.? (????-??-??) [?]
|
||||||
|
|
||||||
|
** 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]
|
* Noteworthy changes in release 3.2.3 (2018-12-18) [stable]
|
||||||
|
|
||||||
|
|||||||
46
data/c++.m4
46
data/c++.m4
@@ -244,8 +244,13 @@ m4_define([b4_symbol_type_declare],
|
|||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
basic_symbol ();
|
basic_symbol ();
|
||||||
|
|
||||||
/// Move or copy constructor.
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
basic_symbol (YY_RVREF (basic_symbol) that);
|
/// Move constructor.
|
||||||
|
basic_symbol (basic_symbol&& that);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// Copy constructor.
|
||||||
|
basic_symbol (const basic_symbol& that);
|
||||||
|
|
||||||
]b4_variant_if([[
|
]b4_variant_if([[
|
||||||
/// Constructor for valueless symbols, and symbols from each type.
|
/// Constructor for valueless symbols, and symbols from each type.
|
||||||
@@ -290,8 +295,13 @@ m4_define([b4_symbol_type_declare],
|
|||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
by_type ();
|
by_type ();
|
||||||
|
|
||||||
/// Move or copy constructor.
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
by_type (YY_RVREF (by_type) that);
|
/// Move constructor.
|
||||||
|
by_type (by_type&& that);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// Copy constructor.
|
||||||
|
by_type (const by_type& that);
|
||||||
|
|
||||||
/// The symbol type as needed by the constructor.
|
/// The symbol type as needed by the constructor.
|
||||||
typedef token_type kind_type;
|
typedef token_type kind_type;
|
||||||
@@ -339,14 +349,26 @@ m4_define([b4_public_types_define],
|
|||||||
, location ()])[
|
, location ()])[
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (YY_RVREF (basic_symbol) that)
|
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (basic_symbol&& that)
|
||||||
: Base (YY_MOVE (that))
|
: Base (std::move (that))
|
||||||
, value (]b4_variant_if([], [YY_MOVE (that.value)]))b4_locations_if([
|
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
|
||||||
, location (YY_MOVE (that.location))])[
|
, location (std::move (that.location))])[
|
||||||
{]b4_variant_if([
|
{]b4_variant_if([
|
||||||
b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY],
|
b4_symbol_variant([this->type_get ()], [value], [move],
|
||||||
[YY_MOVE (that.value)])])[
|
[std::move (that.value)])])[
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template <typename Base>
|
||||||
|
]b4_parser_class_name[::basic_symbol<Base>::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],
|
||||||
|
[that.value])])[
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_variant_if([[
|
]b4_variant_if([[
|
||||||
@@ -429,11 +451,11 @@ m4_define([b4_public_types_define],
|
|||||||
{
|
{
|
||||||
that.clear ();
|
that.clear ();
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
|
|
||||||
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& that)
|
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& that)
|
||||||
: type (that.type)
|
: type (that.type)
|
||||||
{}
|
{}
|
||||||
#endif
|
|
||||||
|
|
||||||
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (token_type t)
|
]b4_inline([$1])b4_parser_class_name[::by_type::by_type (token_type t)
|
||||||
: type (yytranslate_ (t))
|
: type (yytranslate_ (t))
|
||||||
|
|||||||
@@ -171,6 +171,14 @@ int main()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// symbol_type: copy constructor.
|
||||||
|
{
|
||||||
|
parser::symbol_type s = parser::make_INT (51);
|
||||||
|
parser::symbol_type s2 = s;
|
||||||
|
assert_eq (s.value.as<int> (), 51);
|
||||||
|
assert_eq (s2.value.as<int> (), 51);
|
||||||
|
}
|
||||||
|
|
||||||
// stack_symbol_type: construction, accessor.
|
// stack_symbol_type: construction, accessor.
|
||||||
{
|
{
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
|
|||||||
Reference in New Issue
Block a user