glr2.cc: fix glr_stack_item::setState

A glr_stack_item has "raw" memory to store either a glr_state or a
semantic_option.  glr_stack_item::setState stores a state using a copy
assignment.  However, this is more like a construction: we are
starting from "raw" memory, so use the placement new operator instead.
While it probably makes no difference when parse.assert is disabled,
it does make one when it is: the constructor properly initialize the
magic number, the assignment does not.  So without these changes, the
next commit (which stores genuine objects in semantic values) fails
tests 712 and 730 because of incorrect magic numbers.

* data/skeletons/glr2.cc (glr_stack_item::setState): Build the state,
don't just copy it.
This commit is contained in:
Akim Demaille
2020-12-18 06:29:14 +01:00
parent 640b1313d7
commit 0a6c2e6400

View File

@@ -1235,8 +1235,7 @@ public:
// is in unused state (in the list of free items), when parse.assert
// is set.
is_state_ = true;
void *yyp = raw_;
static_cast<glr_state*> (yyp)->copyFrom (state);
new (&raw_) glr_state (state);
}
glr_state& getState ()