mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 22:03:02 +00:00
c++: fix double free when a symbol_type was moved
Currently the following piece of code crashes (with parse.assert),
because we don't record that s was moved-from, and we invoke its dtor.
{
auto s = parser::make_INT (42);
auto s2 = std::move (s);
}
Reported by Wolfgang Thaller.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00077.html
* data/c++.m4 (by_type): Provide a move-ctor.
(basic_symbol): Be sure not to read a moved-from value.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check this case.
This commit is contained in:
11
tests/c++.at
11
tests/c++.at
@@ -160,6 +160,17 @@ int main()
|
||||
assert_eq (s.value.as<int> (), 12);
|
||||
}
|
||||
|
||||
// symbol_type: move constructor.
|
||||
#if 201103L <= YY_CPLUSPLUS
|
||||
{
|
||||
auto s = parser::make_INT (42);
|
||||
auto s2 = std::move (s);
|
||||
assert_eq (s2.value.as<int> (), 42);
|
||||
// Used to crash here, because s was improperly cleared, and
|
||||
// its destructor tried to delete its (moved) value.
|
||||
}
|
||||
#endif
|
||||
|
||||
// stack_symbol_type: construction, accessor.
|
||||
{
|
||||
#if 201103L <= YY_CPLUSPLUS
|
||||
|
||||
Reference in New Issue
Block a user