lalr1.cc: fix stack symbol move

In some casing, once we moved a stack symbol, we forget to mark the
source stack symbol as emptied.  As a consequence, it may be destroyed
a second time.

This happens when the stack has to be resized.

* data/lalr1.cc (stack_symbol_type::stack_symbol_type): Record that
the source was emptied.
(stack_symbol_type::operator=): Likewise.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Force the stack
to be resized.  Check its content.
This commit is contained in:
Akim Demaille
2018-10-18 07:07:32 +02:00
parent b994c3bf78
commit 3967e46a2d
2 changed files with 20 additions and 6 deletions

View File

@@ -162,19 +162,27 @@ int main()
std::cerr << ss.value.as<int>() << '\n';
}
// pushing on the stack.
// Pushing on the stack.
// Sufficiently many so that it will be resized.
// Probably 3 times (starting at 200).
{
parser::stack_type st;
for (int i = 0; i < 100; ++i)
const int mucho = 1700;
for (int i = 0; i < mucho; ++i)
{
#if defined __cplusplus && 201103L <= __cplusplus
st.push(parser::stack_symbol_type{1, parser::make_INT(123)});
st.push(parser::stack_symbol_type{1, parser::make_INT (i)});
#else
parser::symbol_type s = parser::make_INT(123);
parser::stack_symbol_type ss(1, s);
st.push(ss);
parser::symbol_type s = parser::make_INT (i);
parser::stack_symbol_type ss (1, s);
st.push (ss);
#endif
}
for (int i = mucho - 1; 0 <= i; --i)
{
assert (st[0].value.as<int>() == i);
st.pop ();
}
}
}
]])