From 0a6c2e6400bf0641d70b136d5d74b42aac263312 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 18 Dec 2020 06:29:14 +0100 Subject: [PATCH] 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. --- data/skeletons/glr2.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index af56ab70..038b80f5 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -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 (yyp)->copyFrom (state); + new (&raw_) glr_state (state); } glr_state& getState ()