help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About %destructor is c++ mode


From: Hans Åberg
Subject: Re: About %destructor is c++ mode
Date: Fri, 19 Aug 2016 10:15:32 +0200

> On 19 Aug 2016, at 05:50, Min Wang <address@hidden> wrote:

> on another thread at:
> http://lists.gnu.org/archive/html/bug-bison/2016-08/msg00006.html

I am on that list, too.

> it seems I could use std::unique_ptr as the semantic value , but need one
> hack
> 
> -      return *new (yyas_<T> ()) T (t);
> +      return *new (yyas_<T> ()) T (std::move((T&)t));

The issue is that in the original C parser, the implicit $$ = $1 that occurs 
when not writing an explicit action is always executed first before any other 
eventual action. In C this is fine, and not so so expensive as there are no 
copy constructors. This implementation was carried over at least in the 
original C++ parser.

When you then use the std::unique_ptr in $1 it will first implicitly move over 
to $$, and if trying to access $1 explicitly in an action, the pointer is dead.

So the hack depends on what the C++ implementation currently is, which may 
change.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]