From MAILER-DAEMON Thu Aug 18 11:37:04 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baPNQ-00051i-0S
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 11:37:04 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49165)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baPNO-0004zp-6U
	for bug-bison@gnu.org; Thu, 18 Aug 2016 11:37:03 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baPNM-00055J-Mh
	for bug-bison@gnu.org; Thu, 18 Aug 2016 11:37:02 -0400
Received: from mail-oi0-x230.google.com ([2607:f8b0:4003:c06::230]:34261)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baPNM-00055E-Gt
	for bug-bison@gnu.org; Thu, 18 Aug 2016 11:37:00 -0400
Received: by mail-oi0-x230.google.com with SMTP id l203so27227424oib.1
	for <bug-bison@gnu.org>; Thu, 18 Aug 2016 08:37:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:from:date:message-id:subject:to;
	bh=NkSrdDehmk//LaKhfudulwfAPJ4/giOo3XzB4JJgzGw=;
	b=iKwL9jV2OZU82WyW2b4nMvxf1gIAMoZA8Anq9/eshgW8f4yyvAlbcN+7lOdpJ7lWog
	3d02iR4aaYTp3pa0oSKyT5kVKVsSXadBYLBRRRod7uDvHKHQcMfwRyicCugtNEt4vzbe
	WgqgUkJxJjgKuf9tFns6E6VKq1NXiU7iQFwi1+ctSULzkbTqVWwiBMTjsg15DNr16OjC
	aMtT5XOdFSpYhNpU1v8vo1MIi5u05X6p0SuXCI26zWGS1PYQtHsLGLl07kktgJyIr8/9
	wAEd27k7AqoTm7+CnlyyzF/Ui4AUgOn4Ztsw3B2U/2956QN0dqvFOA+15Rewg/I1aT9g
	NEOg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
	bh=NkSrdDehmk//LaKhfudulwfAPJ4/giOo3XzB4JJgzGw=;
	b=MWrdNdyJpSRWYL2AI78wUK8uHpXKUNvFrLk7q+T0z9U2BjDMOAxzVBa9moZXa9ViH1
	KfVihuRujW3E4P5Zr8HuF4CLczsALvRXCip2hPZQyZmkrpMF03qZMWbRFeaCiUsKxJeN
	MsFWpTqdNS9yHAUkQ7F6H7z1dYvs6ZRNWLFoE/3s0ERsyFJMoGNhZAHULV8znpR3XqK6
	51LzqlaTMXFy8lzGlTg4CoOO5gmgxz4x6ovAg841FopI+R3U+Ww3fHI9m+FxbdaHx2Xe
	Vlhnu/32eI/KiHjvPsMmiwabr3mdjzr7pHO7HCBcTE0+u3nYgyhPmqACVAfRN7+pPhJm
	0FHg==
X-Gm-Message-State: AEkoout9UWx+Kjba6Y+Q4otMbDRrIBSl2YlLoO4bJpdPIDt1SSzK/kv21mbbb2ylj+iEZYX+D6BZsUPlH5IstQ==
X-Received: by 10.157.1.163 with SMTP id e32mr1906762ote.175.1471534619804;
	Thu, 18 Aug 2016 08:36:59 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.182.215.138 with HTTP; Thu, 18 Aug 2016 08:36:59 -0700 (PDT)
From: Min Wang <mingewang@gmail.com>
Date: Thu, 18 Aug 2016 11:36:59 -0400
Message-ID: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
Subject: bison 3.0.4 %destructor is c++ mode seems to be called even in the
	normal parse
To: bug-bison@gnu.org
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2607:f8b0:4003:c06::230
Content-Type: text/plain; charset=UTF-8
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 15:37:03 -0000

HI

In bison 3.0.4, the  %destructor seems to be called even in the normal parse

we have discussion at help-bison mailing list.

The thread started at:

http://lists.gnu.org/archive/html/help-bison/2016-08/msg00014.html

more verbose ouput details is at:

http://lists.gnu.org/archive/html/help-bison/2016-08/msg00016.html


but briefly,


in the generated parser.cpp:

#line 1038 "filter_parser.cpp" // lalr1.cc:859
      YY_REDUCE_PRINT (yyn);

      try

        {

          switch (yyn)

            {
                 ....
            default:

              break;

            }

        }

      catch (const syntax_error& yyexc)

        {

          error (yyexc);

          YYERROR;

        }

      YY_SYMBOL_PRINT ("-> $$ =", yylhs);

      yypop_ (yylen);

      yylen = 0;

      YY_STACK_PRINT ();

in the generated : filter_parser.hh

    /// Stack type.

    typedef stack<stack_symbol_type> stack_type;

    /// The stack.
    stack_type yystack_;

filter_parser::basic_symbol<Base>::clear ()  {
    ...
        basic_symbol<Base>& yysym = *this;
    (void) yysym;
    switch (yytype)
    {
      case 25: // PROG
#line 159 "filter_parser.yy" // lalr1.cc:377

        { std::cout << " **** I am PROG " << yysym.value.template as<
PROG*>* () ;*
              delete $$;
              std::cout << " delete done" << std::endl;
        }



even in  the normal case ( no error recovery ), the call flow will go to:

yypop_ (yylen)  -> yystack_.pop (n) -> basic_symbol<Base>::clear () ->
call %destructor code



Could someone check it?


thanks.




min

From MAILER-DAEMON Thu Aug 18 13:13:10 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baQsQ-0003Yi-DX
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 13:13:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:44051)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kaz@kylheku.com>) id 1baQsN-0003YV-P5
	for bug-bison@gnu.org; Thu, 18 Aug 2016 13:13:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <kaz@kylheku.com>) id 1baQsM-000194-OB
	for bug-bison@gnu.org; Thu, 18 Aug 2016 13:13:07 -0400
Received: from smtp-out-so.shaw.ca ([64.59.136.139]:59189)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kaz@kylheku.com>)
	id 1baQsF-00015M-B2; Thu, 18 Aug 2016 13:12:59 -0400
Received: from kylheku.com ([24.85.175.81]) by shaw.ca with SMTP
	id aQs0bp4yKeXEcaQs1bl9Jz; Thu, 18 Aug 2016 11:12:46 -0600
X-Authority-Analysis: v=2.2 cv=T/3OdLCQ c=1 sm=1 tr=0
	a=WiYoHcCliNeVponEdG0Ckg==:117 a=WiYoHcCliNeVponEdG0Ckg==:17
	a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=7z1cN_iqozsA:10
	a=tlJQu23w43CmwIjlkMoA:9
Received: from www-data by kylheku.com with local (Exim 4.72)
	(envelope-from <kaz@kylheku.com>)
	id 1baQry-0003cq-NK; Thu, 18 Aug 2016 10:12:42 -0700
To: Min Wang <mingewang@gmail.com>
Subject: Re: bison 3.0.4 %destructor is c++ mode seems to be called even in
	the normal parse
X-PHP-Originating-Script: 501:rcmail.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8;
 format=flowed
Content-Transfer-Encoding: quoted-printable
Date: Thu, 18 Aug 2016 10:12:42 -0700
From: Kaz Kylheku <kaz@kylheku.com>
Cc: bug-bison@gnu.org, bug-bison <bug-bison-bounces+kaz=kylheku.com@gnu.org>
In-Reply-To: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
References: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
Message-ID: <6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
X-Sender: kaz@kylheku.com
User-Agent: Roundcube Webmail/0.9.2
X-CMAE-Envelope: MS4wfA23uaRJxYSoy0oJcpnrPo54eevpi7+9fWVZvALSO4xxG2p73MCbqx7GKjEGJEN2deqimznoOqy76ZouxX1asPE9/pMIqSNgeQPOQFuojWCWl8wUHX+6
	asGUlFc9FNyDBSceFVpwy6Jm6NJ8fHkgVn1keQUqXpn1gheMBzTc+ENCIExt7DrSIhfKDSX4oeHilpRJCKqnMhRUm9E5hBXnmDmyQ3g0OtTIwdqaEs/is97B
	RqLfz7d5RONi7zKMVJ/pOw==
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 64.59.136.139
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 17:13:09 -0000

On 18.08.2016 08:36, Min Wang wrote:
> HI
>=20
> In bison 3.0.4, the  %destructor seems to be called even in the normal=20
> parse

In your example program you are using "Variants" rather
than %union. That's a very special C++-specific Bison feature.

It seems that there is no reason to use %destructor if you're
using variants. If any of the variants are pointers, they can
just be smart pointers; they don't have to be low level pointers.

Can you confirm whether %destructor is still called in the
normal parse if instead of:

   %type <PROG*> PROG
   %type <ListExp*> ListExp

you use

   %union {
     PROG *PROG;
     ListExp *ListExp;
   }

That is to say, is this a issue specific to variants, or does it
affect C++ parsers regardless of whether %union or variants
are used?

If under %union, %destructor is correctly called only during
error recovery (the issue is absent) then just use %union,
since all your semantic value types are pointers. Then be sure
you have all the right delete calls in your grammar actions.

If you use variants, it seems you can side-step the issue
by not using pointers. If the values are smart pointers,
then there is no problem, because a rule like:

    foo : bar { $$ =3D $1; }

will handle the transfer from $1 to $$ using the smart pointer
assignment operator, allowing $1 to then be safely destroyed
by its destructor.

It does seem that you have discovered at least this bug,
or deviation from documented behavior: when plain pointer types
are used in variant declarations in a C++ parser, and %destructor
is used to free them in all circumstances.

So for instance, suppose that we use the type <char *>,
and we have a %destructor which calls free. In a C parser,
we might just have this:

    foo : bar { $$ =3D $1; }  /* transfer ownership of pointer */

But under C++ Bison with variants, we must do:

    foo : bar { $$ =3D strdup($1); } /* $1 %destructor will kick in */

Or perhaps this will work:

    foo : bar { $$ =3D $1;
                $1 =3D NULL; } /* Spare $1 from jaws of %destructor */





From MAILER-DAEMON Thu Aug 18 15:05:17 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baScv-0003T3-GN
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 15:05:17 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35623)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baScr-0003Qa-Md
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:05:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baSco-0006Qp-DJ
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:05:12 -0400
Received: from mail-oi0-x22b.google.com ([2607:f8b0:4003:c06::22b]:36337)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>)
	id 1baSco-0006Qb-5i; Thu, 18 Aug 2016 15:05:10 -0400
Received: by mail-oi0-x22b.google.com with SMTP id f189so34822756oig.3;
	Thu, 18 Aug 2016 12:05:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=o4IuVndznJqXo5szPG5xj7cWDrQpJKXXLsI1lDIcLpw=;
	b=0+VycL5oDAixzlGpU082PmfgfvbMOLMn4mmgM07rtYyOViwrAcIxRl405uHYcirTz3
	o7Byf+QCCm5kdjO5Z9w9njy6ANgfE6efwF4/Zq0jH+o7gjvnlAy0Ve7ayO+Adp5EsfvR
	brZ3aYtfqZrF8vWqhISPXMO2SIW2PmKskhZm58fL7nK/rcI8G34rDHUkWWYvmpL2YxSZ
	aO5RVq8owTHflKpn6XL64wrjzd2CCye2Uf8P2jpRSrmqwlIF6L+ECKaT0xBuSkAPrl2+
	q056+hxCzKe6VmKxXk7zeVmHnUoMmfaZbzWNKgn9YfTb58Mq8u+Ol1fks2Do9FPOSJ8s
	i1Fg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=o4IuVndznJqXo5szPG5xj7cWDrQpJKXXLsI1lDIcLpw=;
	b=anS3n8BrmLI0sAsw2ocwzQNJ/Fwqojv98gy60r82vGrFlY5SraPvZMjY+F8A6P2QXg
	39wcukZLuBLHdBCLcAzwYCkha9FFj14GMVZCLSiDl6WemGUYhjgZRg27QlngME3GeGmi
	1FOvyrd4GnMgdAaX0xcZag9+oYdU5AduKlQvNPXZR1FjUXzdy0Cw9zBgo/pHbLMWp9d3
	qtEks2hJOrW280JrePSyv4yO1FqLH0VySFTw2TfI5tyBpy3Nbb28Z7xjG4N6vG+qKP2D
	rOjfQzQsRcJ++PVaywwJNy/FleV5v8Wit51sJP4QimDamlOiGALW2UfADietBuv9lLMj
	7MAg==
X-Gm-Message-State: AEkoouvDgP+KtbpnioRJzF+6105JuwuxlO2fSe6cxyQTxd33/g0yH5MC44Kv4s8tgvREKRVfqwlkvCtYFiYDOw==
X-Received: by 10.157.39.233 with SMTP id c96mr2333641otb.81.1471547109393;
	Thu, 18 Aug 2016 12:05:09 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.182.215.138 with HTTP; Thu, 18 Aug 2016 12:05:08 -0700 (PDT)
In-Reply-To: <6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
References: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
	<6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
From: Min Wang <mingewang@gmail.com>
Date: Thu, 18 Aug 2016 15:05:08 -0400
Message-ID: <CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
Subject: Re: bison 3.0.4 %destructor is c++ mode seems to be called even in
	the normal parse
To: Kaz Kylheku <kaz@kylheku.com>
Cc: bug-bison@gnu.org, bug-bison <bug-bison-bounces+kaz=kylheku.com@gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2607:f8b0:4003:c06::22b
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 19:05:16 -0000

HI
@kaz. thanks. I will check the %union later

I'like to use the smart pointers ( std::unique_ptr) , but somehow I got
some compiler errors.

here are some details:
e.g:

using PROG_PTR =3D std::unique_ptr<PROG>;
....


%type <PROG_PTR> PROG

%type <ListExp_PTR> ListExp

%type <Exp_PTR> Exp

...


PROG : ListExp      {
                   std::reverse( $1->begin(), $1->end() );
                   // store the result to filter_driver.prog
                   driver.store_ast( new Json_Filter( std::move($1) ) );
                   }
;

ListExp : Exp    {
                         ListExp_PTR tmp( new ListExp() ) ;
                         tmp->push_back( std::move($1) );
                         std::swap( $$, tmp );
                       }

//some classes

class PROG : public Visitable

{

public:

    virtual ~PROG() {};



};

// real one here

using ListExp_PTR =3D std::unique_ptr<ListExp>;



class Json_Filter : public PROG

{

public:

  ListExp_PTR listexp_;



  Json_Filter(ListExp_PTR p1) : listexp_( std::move(p1) ) {}

  ~Json_Filter() {}



};

// should not inherit vector here, put here just for testing now.
class ListExp : public Visitable, public std::vector<Exp_PTR>

{

public:

};



but I got those errors:
....

In file included from filter_parser.cpp:46:0:

filter_parser.hh: In instantiation of =E2=80=98T&
brc_filter::variant<S>::build(const T&) [with T =3D std::unique_ptr<ListExp=
>;
long unsigned int S =3D 8ul]=E2=80=99:
filter_parser.hh:241:12:   required from =E2=80=98void
brc_filter::variant<S>::copy(const self_type&) [with T =3D
std::unique_ptr<ListExp>; long unsigned int S =3D 8ul;
brc_filter::variant<S>::self_type =3D brc_filter::variant<8ul>]=E2=80=99
filter_parser.cpp:353:46:   required from here

filter_parser.hh:184:37: error: use of deleted function
=E2=80=98std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _=
Dp>&)
[with _Tp =3D ListExp; _Dp =3D std::default_delete<ListExp>]=E2=80=99
       return *new (yyas_<T> ()) T (t);

                                     ^

In file included from /usr/include/c++/4.9/memory:81:0,

                 from syntax.hh:6,

                 from filter_parser.yy:46,

                 from filter_parser.cpp:46:

/usr/include/c++/4.9/bits/unique_ptr.h:356:7: note: declared here

       unique_ptr(const unique_ptr&) =3D delete;

....

the filter_parser.hh:184  is:

    /// Instantiate a \a T in here from \a t.

    template <typename T>

    T&

    build (const T& t)

    {

      YYASSERT (!yytypeid_);

      YYASSERT (sizeof (T) <=3D S);

      yytypeid_ =3D & typeid (T);

      return *new (yyas_<T> ()) T (t);

    }


seems the build function somehow is not right?


thanks


min

On Thu, Aug 18, 2016 at 1:12 PM, Kaz Kylheku <kaz@kylheku.com> wrote:

> On 18.08.2016 08:36, Min Wang wrote:
>
>> HI
>>
>> In bison 3.0.4, the  %destructor seems to be called even in the normal
>> parse
>>
>
> In your example program you are using "Variants" rather
> than %union. That's a very special C++-specific Bison feature.
>
> It seems that there is no reason to use %destructor if you're
> using variants. If any of the variants are pointers, they can
> just be smart pointers; they don't have to be low level pointers.
>
> Can you confirm whether %destructor is still called in the
> normal parse if instead of:
>
>   %type <PROG*> PROG
>   %type <ListExp*> ListExp
>
> you use
>
>   %union {
>     PROG *PROG;
>     ListExp *ListExp;
>   }
>
> That is to say, is this a issue specific to variants, or does it
> affect C++ parsers regardless of whether %union or variants
> are used?
>
> If under %union, %destructor is correctly called only during
> error recovery (the issue is absent) then just use %union,
> since all your semantic value types are pointers. Then be sure
> you have all the right delete calls in your grammar actions.
>
> If you use variants, it seems you can side-step the issue
> by not using pointers. If the values are smart pointers,
> then there is no problem, because a rule like:
>
>    foo : bar { $$ =3D $1; }
>
> will handle the transfer from $1 to $$ using the smart pointer
> assignment operator, allowing $1 to then be safely destroyed
> by its destructor.
>
> It does seem that you have discovered at least this bug,
> or deviation from documented behavior: when plain pointer types
> are used in variant declarations in a C++ parser, and %destructor
> is used to free them in all circumstances.
>
> So for instance, suppose that we use the type <char *>,
> and we have a %destructor which calls free. In a C parser,
> we might just have this:
>
>    foo : bar { $$ =3D $1; }  /* transfer ownership of pointer */
>
> But under C++ Bison with variants, we must do:
>
>    foo : bar { $$ =3D strdup($1); } /* $1 %destructor will kick in */
>
> Or perhaps this will work:
>
>    foo : bar { $$ =3D $1;
>                $1 =3D NULL; } /* Spare $1 from jaws of %destructor */
>
>
>
>


--=20
http://www.comrite.com

From MAILER-DAEMON Thu Aug 18 15:16:55 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baSoB-0007WV-Bi
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 15:16:55 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39136)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baSo8-0007WO-HE
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:16:54 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baSo5-0000pK-3h
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:16:51 -0400
Received: from mail-oi0-x233.google.com ([2607:f8b0:4003:c06::233]:35729)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>)
	id 1baSo4-0000pA-RO; Thu, 18 Aug 2016 15:16:49 -0400
Received: by mail-oi0-x233.google.com with SMTP id 4so35357150oih.2;
	Thu, 18 Aug 2016 12:16:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=URiTi8sQWBTo6xyaO1o5wSq77G4BbfScvyT69wnvLu4=;
	b=CPFO/QFd1TttRdbG8AIxyZqLbHSCU98hA9AObCkVvra3txp3tMIQAqqY5PvtgL9Rag
	FeQxX2UiQSA3x6Po+N2TSs29DzIbQeA7cV+etQjWSXkdHjMVCrDi+AXUyDgEs2x/tkXP
	HcRZqZuMCoOnoJCl5fONO/VEQV0JKoAdYxd6Xj7PFM23UQkbMMSjf2pfCIqDktpcLujd
	Ie4PUg1qSemqz9DFKV5TdGmy76Idek4pFSeB1u+TtYaI9KRBEF+5tLRZeeduXrlWoyD1
	v/YLZOgSGSb5BEC8wz1xxtm3aGzN64APCoRgSvpeCGnLWz9JATVWA/6qLpthO17e1bGU
	hXqQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=URiTi8sQWBTo6xyaO1o5wSq77G4BbfScvyT69wnvLu4=;
	b=C4yQC76JfNcKEhK7K04tMqI7vUCFIg2oEc9v571A9FNViqnb8fM4QafseWACQBLsBY
	tLpz2naKs8+04MdJun+/wvWKiOnlC85AjsLQo5M6lK3onzQVlzCn2pyraCXnbughVj63
	OrzV2PJN4XeBet76+PuBu+JXAyJRWvFCuhVrPl1ciNUOOvMzZJEiiMbKRRYpaEhuTUm7
	kFWTJREEWLzX4T41pHvPrPfnMhhGHFl+jDGcQFR/N+tSM9Cea96XWn2GvFIYpWUfU+H/
	pvXY99z/sCC5/Cl/K0V650wEH0pNFfRV/f2cVdWgbSYvmsUrJevTp9USxNmOjjfWEyYd
	vJUQ==
X-Gm-Message-State: AEkoouv284KJ4kJ7eZK8+bSoXuacy2ClKDlLtxLo228JMeIxfPTLWvB7owyzPbSf5zHS2nuOs2Pus7kPWFu/LQ==
X-Received: by 10.157.18.235 with SMTP id g98mr2478714otg.98.1471547808263;
	Thu, 18 Aug 2016 12:16:48 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.182.215.138 with HTTP; Thu, 18 Aug 2016 12:16:47 -0700 (PDT)
In-Reply-To: <CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
References: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
	<6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
	<CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
From: Min Wang <mingewang@gmail.com>
Date: Thu, 18 Aug 2016 15:16:47 -0400
Message-ID: <CADn_AD-TpPkwh9LwmKxjAPQ1bU4sbbztH6hSYb4Je74XmRrL=w@mail.gmail.com>
Subject: Re: bison 3.0.4 %destructor is c++ mode seems to be called even in
	the normal parse
To: Kaz Kylheku <kaz@kylheku.com>
Cc: bug-bison@gnu.org, bug-bison <bug-bison-bounces+kaz=kylheku.com@gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2607:f8b0:4003:c06::233
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 19:16:54 -0000

HI

Also

http://lists.gnu.org/archive/html/bug-bison/2015-01/msg00066.html

seems indicated bison does not support std::unique_ptr as a semantic values


min




On Thu, Aug 18, 2016 at 3:05 PM, Min Wang <mingewang@gmail.com> wrote:

> HI
> @kaz. thanks. I will check the %union later
>
> I'like to use the smart pointers ( std::unique_ptr) , but somehow I got
> some compiler errors.
>
> here are some details:
> e.g:
>
> using PROG_PTR =3D std::unique_ptr<PROG>;
> ....
>
>
> %type <PROG_PTR> PROG
>
> %type <ListExp_PTR> ListExp
>
> %type <Exp_PTR> Exp
>
> ...
>
>
> PROG : ListExp      {
>                    std::reverse( $1->begin(), $1->end() );
>                    // store the result to filter_driver.prog
>                    driver.store_ast( new Json_Filter( std::move($1) ) );
>                    }
> ;
>
> ListExp : Exp    {
>                          ListExp_PTR tmp( new ListExp() ) ;
>                          tmp->push_back( std::move($1) );
>                          std::swap( $$, tmp );
>                        }
>
> //some classes
>
> class PROG : public Visitable
>
> {
>
> public:
>
>     virtual ~PROG() {};
>
>
>
> };
>
> // real one here
>
> using ListExp_PTR =3D std::unique_ptr<ListExp>;
>
>
>
> class Json_Filter : public PROG
>
> {
>
> public:
>
>   ListExp_PTR listexp_;
>
>
>
>   Json_Filter(ListExp_PTR p1) : listexp_( std::move(p1) ) {}
>
>   ~Json_Filter() {}
>
>
>
> };
>
> // should not inherit vector here, put here just for testing now.
> class ListExp : public Visitable, public std::vector<Exp_PTR>
>
> {
>
> public:
>
> };
>
>
>
> but I got those errors:
> ....
>
> In file included from filter_parser.cpp:46:0:
>
> filter_parser.hh: In instantiation of =E2=80=98T& brc_filter::variant<S>:=
:build(const
> T&) [with T =3D std::unique_ptr<ListExp>; long unsigned int S =3D 8ul]=E2=
=80=99:
> filter_parser.hh:241:12:   required from =E2=80=98void
> brc_filter::variant<S>::copy(const self_type&) [with T =3D
> std::unique_ptr<ListExp>; long unsigned int S =3D 8ul;
> brc_filter::variant<S>::self_type =3D brc_filter::variant<8ul>]=E2=80=99
> filter_parser.cpp:353:46:   required from here
>
> filter_parser.hh:184:37: error: use of deleted function
> =E2=80=98std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp,=
 _Dp>&)
> [with _Tp =3D ListExp; _Dp =3D std::default_delete<ListExp>]=E2=80=99
>        return *new (yyas_<T> ()) T (t);
>
>                                      ^
>
> In file included from /usr/include/c++/4.9/memory:81:0,
>
>                  from syntax.hh:6,
>
>                  from filter_parser.yy:46,
>
>                  from filter_parser.cpp:46:
>
> /usr/include/c++/4.9/bits/unique_ptr.h:356:7: note: declared here
>
>        unique_ptr(const unique_ptr&) =3D delete;
>
> ....
>
> the filter_parser.hh:184  is:
>
>     /// Instantiate a \a T in here from \a t.
>
>     template <typename T>
>
>     T&
>
>     build (const T& t)
>
>     {
>
>       YYASSERT (!yytypeid_);
>
>       YYASSERT (sizeof (T) <=3D S);
>
>       yytypeid_ =3D & typeid (T);
>
>       return *new (yyas_<T> ()) T (t);
>
>     }
>
>
> seems the build function somehow is not right?
>
>
> thanks
>
>
> min
>
> On Thu, Aug 18, 2016 at 1:12 PM, Kaz Kylheku <kaz@kylheku.com> wrote:
>
>> On 18.08.2016 08:36, Min Wang wrote:
>>
>>> HI
>>>
>>> In bison 3.0.4, the  %destructor seems to be called even in the normal
>>> parse
>>>
>>
>> In your example program you are using "Variants" rather
>> than %union. That's a very special C++-specific Bison feature.
>>
>> It seems that there is no reason to use %destructor if you're
>> using variants. If any of the variants are pointers, they can
>> just be smart pointers; they don't have to be low level pointers.
>>
>> Can you confirm whether %destructor is still called in the
>> normal parse if instead of:
>>
>>   %type <PROG*> PROG
>>   %type <ListExp*> ListExp
>>
>> you use
>>
>>   %union {
>>     PROG *PROG;
>>     ListExp *ListExp;
>>   }
>>
>> That is to say, is this a issue specific to variants, or does it
>> affect C++ parsers regardless of whether %union or variants
>> are used?
>>
>> If under %union, %destructor is correctly called only during
>> error recovery (the issue is absent) then just use %union,
>> since all your semantic value types are pointers. Then be sure
>> you have all the right delete calls in your grammar actions.
>>
>> If you use variants, it seems you can side-step the issue
>> by not using pointers. If the values are smart pointers,
>> then there is no problem, because a rule like:
>>
>>    foo : bar { $$ =3D $1; }
>>
>> will handle the transfer from $1 to $$ using the smart pointer
>> assignment operator, allowing $1 to then be safely destroyed
>> by its destructor.
>>
>> It does seem that you have discovered at least this bug,
>> or deviation from documented behavior: when plain pointer types
>> are used in variant declarations in a C++ parser, and %destructor
>> is used to free them in all circumstances.
>>
>> So for instance, suppose that we use the type <char *>,
>> and we have a %destructor which calls free. In a C parser,
>> we might just have this:
>>
>>    foo : bar { $$ =3D $1; }  /* transfer ownership of pointer */
>>
>> But under C++ Bison with variants, we must do:
>>
>>    foo : bar { $$ =3D strdup($1); } /* $1 %destructor will kick in */
>>
>> Or perhaps this will work:
>>
>>    foo : bar { $$ =3D $1;
>>                $1 =3D NULL; } /* Spare $1 from jaws of %destructor */
>>
>>
>>
>>
>
>
> --
> http://www.comrite.com
>
>
>
>


--=20
http://www.comrite.com

From MAILER-DAEMON Thu Aug 18 15:37:59 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baT8Z-0003Hk-Sr
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 15:37:59 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:43157)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kaz@kylheku.com>) id 1baT8X-0003Hd-La
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:37:58 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <kaz@kylheku.com>) id 1baT8W-00052R-Ry
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:37:57 -0400
Received: from smtp-out-no.shaw.ca ([64.59.134.9]:56467)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kaz@kylheku.com>)
	id 1baT8Q-00051r-Ky; Thu, 18 Aug 2016 15:37:50 -0400
Received: from kylheku.com ([24.85.175.81]) by shaw.ca with SMTP
	id aT8NblHjqXHJlaT8Ob2MCi; Thu, 18 Aug 2016 13:37:49 -0600
X-Authority-Analysis: v=2.2 cv=Ffh1/926 c=1 sm=1 tr=0
	a=WiYoHcCliNeVponEdG0Ckg==:117 a=WiYoHcCliNeVponEdG0Ckg==:17
	a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=7z1cN_iqozsA:10
	a=rrXOo0DV_qWcXNbHEcsA:9
Received: from www-data by kylheku.com with local (Exim 4.72)
	(envelope-from <kaz@kylheku.com>)
	id 1baT8M-0006hu-0j; Thu, 18 Aug 2016 12:37:46 -0700
To: Min Wang <mingewang@gmail.com>
Subject: Re: bison 3.0.4 %destructor is c++ mode seems to be called even in
	the normal parse
X-PHP-Originating-Script: 501:rcmail.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8;
 format=flowed
Content-Transfer-Encoding: quoted-printable
Date: Thu, 18 Aug 2016 12:37:45 -0700
From: Kaz Kylheku <kaz@kylheku.com>
Cc: bug-bison@gnu.org, bug-bison <bug-bison-bounces+kaz=kylheku.com@gnu.org>
In-Reply-To: <CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
References: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
	<6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
	<CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
Message-ID: <1c6a8d29adb0556a32d74d81a0ad76b5@mail.kylheku.com>
X-Sender: kaz@kylheku.com
User-Agent: Roundcube Webmail/0.9.2
X-CMAE-Envelope: MS4wfAao/6tjbXoAal8AqFWwJXZmwuB+ySs95dFDRFoxHABwhoguDG/3PiLcoaygtfz5fEzX5V3OA5v6DAaU0txlaY+GXoSlvlPgws9sF/S8XKQguNL6uB5l
	Io4NY+GTfyuaDfhn02fhkHt1z0FWsutS4MihjseTvAzZgiyNnszDFqjbgpHhlaqED5OWbKg3EYMg64q8DPpVzHv6ULbJmoJ2oOKj1OmM/xQUEjDjr9qpGLow
	+GYlcoxXKfs+900ySZ+yGQ==
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 64.59.134.9
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 19:37:58 -0000

On 18.08.2016 12:05, Min Wang wrote:
> HI
> @kaz. thanks. I will check the %union later
>=20
> I'like to use the smart pointers ( std::unique_ptr) , but somehow I got=
=20
> some compiler errors.
>=20
> here are some details:
> e.g:
>=20
> using PROG_PTR =3D std::unique_ptr<PROG>;

"using" is now a full-blown alternative for typedef?

I don't keep up closely with the C++ standard.

The old-fashioned way is:

  typedef std::unique_ptr<PROG> PROG_PTR;

The "using" that I remember was purely for bringing long, qualified=20
names into the current scope as short names, not for creating alias=20
names for types.

  using foo::bar::baz; // the unqualified name baz can now be used in=20
this scope


From MAILER-DAEMON Thu Aug 18 15:54:43 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baTOl-00084S-M4
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 15:54:43 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:46584)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baTOj-00084H-Ki
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:54:42 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baTOi-0008ID-9d
	for bug-bison@gnu.org; Thu, 18 Aug 2016 15:54:41 -0400
Received: from mail-oi0-x22d.google.com ([2607:f8b0:4003:c06::22d]:35337)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>)
	id 1baTOi-0008I9-4E; Thu, 18 Aug 2016 15:54:40 -0400
Received: by mail-oi0-x22d.google.com with SMTP id 4so36661512oih.2;
	Thu, 18 Aug 2016 12:54:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=olfNr+CGe70XUeD/uHUVnn/M9DHHewHeP7Q32Yh1kMw=;
	b=L5DGKFEmxEIvUt8v0sQYWyNeMndLhY6JFV2fKlQy0vNu2MfsuIdzOhcp/+/3nWsD+j
	aDCXLhUcUEEx5LuP99O6U/ginvjsjdW9Msn4LprpizYMUwgiZdWnpkTgEO0hbTxAIVDm
	r8cl+MK5rBoKm7/aMovUkXPwHEKiS9J5bkkjKcP+UgB9KrqL2pCMQ2waXEI3iZ79inLe
	kdLrmg6ybqqhfVqQhY/4nFca5/TR1PJPAI5CiULBb/LKOj0piZhd3cd56y/JYbAXCKWN
	MkMkYUUuCEr6xW36aiO30skZSEU0rY1HbtTQSSIzY9SVZu6UDFkwW7nlmzviJbRBBvkk
	Vk4g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=olfNr+CGe70XUeD/uHUVnn/M9DHHewHeP7Q32Yh1kMw=;
	b=GqHl+sw0u7jNZIvcjvyd79R3Xb0V+jGcd27rXztbOU+uW+soqRlZweIu6pB/3Nva6q
	BTGKR7FOFM3c9LNCAcsvBXQcQDeVAGo3zd76yho6eKW2wPNqiOAw1dUUr9Lx3WHe+IpM
	aeKyjpfFycHquyA7aHDdGWkqQ+TgQk+ElQ5FIIM2wgL0sRyNzGGn2FWXr97AG2bMgaAV
	Q8vaEzAPUxACMX8qPSfGxZPN4WDn3uU/3D4LBYR1hqq45rPDG+0ywClm65RyWhoe3dz+
	6gOCN/5RdTlG6UqA6ToeJHNfs7k7fhDbYkdJeF4qYMtV7/42WRnPY3PJuMqUgPIDuQY/
	4T1A==
X-Gm-Message-State: AEkoouvu7RDSrMkvApmv2zDtjb/1GGsv72y+f1fIFWwqRvKFaCxmaBkiu+01nDDxuUT6MaKwumzbzPWv3cXtBQ==
X-Received: by 10.202.206.20 with SMTP id e20mr2293496oig.136.1471550079528;
	Thu, 18 Aug 2016 12:54:39 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.182.215.138 with HTTP; Thu, 18 Aug 2016 12:54:39 -0700 (PDT)
In-Reply-To: <1c6a8d29adb0556a32d74d81a0ad76b5@mail.kylheku.com>
References: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
	<6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
	<CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
	<1c6a8d29adb0556a32d74d81a0ad76b5@mail.kylheku.com>
From: Min Wang <mingewang@gmail.com>
Date: Thu, 18 Aug 2016 15:54:39 -0400
Message-ID: <CADn_AD_=goTXBuvjoYEnxabCUnO-jCH9TJDZih6cBedLCD=acg@mail.gmail.com>
Subject: Re: bison 3.0.4 %destructor is c++ mode seems to be called even in
	the normal parse
To: Kaz Kylheku <kaz@kylheku.com>
Cc: bug-bison@gnu.org, bug-bison <bug-bison-bounces+kaz=kylheku.com@gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2607:f8b0:4003:c06::22d
Content-Type: text/plain; charset=UTF-8
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 19:54:42 -0000

HI

@kaz. yes, "using" is a  alternative new typedef ( c++11).


min

On Thu, Aug 18, 2016 at 3:37 PM, Kaz Kylheku <kaz@kylheku.com> wrote:

> On 18.08.2016 12:05, Min Wang wrote:
>
>> HI
>> @kaz. thanks. I will check the %union later
>>
>> I'like to use the smart pointers ( std::unique_ptr) , but somehow I got
>> some compiler errors.
>>
>> here are some details:
>> e.g:
>>
>> using PROG_PTR = std::unique_ptr<PROG>;
>>
>
> "using" is now a full-blown alternative for typedef?
>
> I don't keep up closely with the C++ standard.
>
> The old-fashioned way is:
>
>  typedef std::unique_ptr<PROG> PROG_PTR;
>
> The "using" that I remember was purely for bringing long, qualified names
> into the current scope as short names, not for creating alias names for
> types.
>
>  using foo::bar::baz; // the unqualified name baz can now be used in this
> scope
>



-- 
http://www.comrite.com

From MAILER-DAEMON Thu Aug 18 16:19:23 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baTmd-0007Zb-R3
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 16:19:23 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54060)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <sasha2048@gmail.com>) id 1baTmb-0007YI-Hf
	for bug-bison@gnu.org; Thu, 18 Aug 2016 16:19:23 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <sasha2048@gmail.com>) id 1baTmY-0006iz-80
	for bug-bison@gnu.org; Thu, 18 Aug 2016 16:19:21 -0400
Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]:35754)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <sasha2048@gmail.com>) id 1baTmX-0006ir-QG
	for bug-bison@gnu.org; Thu, 18 Aug 2016 16:19:18 -0400
Received: by mail-lf0-x234.google.com with SMTP id f93so19329481lfi.2
	for <bug-bison@gnu.org>; Thu, 18 Aug 2016 13:19:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=subject:to:references:from:message-id:date:user-agent:mime-version
	:in-reply-to:content-transfer-encoding;
	bh=iBsJ7tjsUG52BgmzMuzxLwEPEiXIqtUgXgTsc4sYADM=;
	b=TDSj6H9tifc6PphgFf5Xi7SEGVEcRDDZEM/s2aN2Iq0aHCVUn0CEbkPgVaL/odRP0O
	WrRh60XDXH1MEwslVo/04ZV5HxxrHmSMkP8bThVLeLFFYeAQov/aeE0Kg+GUVu4hfU45
	f+hikIgiLwQuhFj4ZqcUHxffxlmv4vt2Pg9LbpvXZ+B1VVoLjf68+zHGDQBLBbIdOdHD
	wf9FKOdnjDfl3OuYHWai/IXoMx0cjXSDY39J3+ut97b3yZwsh3NsPCD81ouz1aOTh+aV
	oYT688WgoKAqUKuyrezuvuN9Vf3OUwf7GA6kfoYQAWAIiRWi4SR2q4xF6dYJvbVx6Da0
	Uyyg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:subject:to:references:from:message-id:date
	:user-agent:mime-version:in-reply-to:content-transfer-encoding;
	bh=iBsJ7tjsUG52BgmzMuzxLwEPEiXIqtUgXgTsc4sYADM=;
	b=g4UBoThHjpHoTKBEAdS0oHCwyoYTpKIOtpsy1pFisc6csoABPz2msdiamYbARlWdhg
	Q9vNHxsbKFLjbAuJVkDog4zHHvKNRqIXZ+hfcs5cArYvsLHR1W00NYH1IMGnflplJcsL
	ZjgZzXgyHzLSIJDs30mfwSIvGQadu4Ss/T0VImP9fTNJnmWPPmtaxUlOaB/Cx9j8ZA+S
	oWw+3d4qpumjIxOc54H/Qt1qQzzD1iXH9PT9r7DW/iDPzI8YTe1hEUK4KWBzpMi75Rqi
	fAIdIx3eD5n3wulRp74NiZRI9qAIAmznoaJKSiiSLxBMeYUsY+2F6Ska2xLJutZTxK1T
	1JCg==
X-Gm-Message-State: AEkoouu0zJK50penQfuLJLJlEALmfMkSLLLGlEbHcCZHss8cEVJWQTvdCezsjjpHIPN05g==
X-Received: by 10.25.151.66 with SMTP id z63mr1246008lfd.159.1471551556190;
	Thu, 18 Aug 2016 13:19:16 -0700 (PDT)
Received: from [192.168.111.115] (founding-chandelier.volia.net. [93.72.16.3])
	by smtp.gmail.com with ESMTPSA id
	u2sm591241lja.16.2016.08.18.13.19.15 for <bug-bison@gnu.org>
	(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Thu, 18 Aug 2016 13:19:15 -0700 (PDT)
Subject: Re: bison 3.0.4 %destructor is c++ mode seems to be called even in
	the normal parse
To: bug-bison@gnu.org
References: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
	<6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
	<CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
	<CADn_AD-TpPkwh9LwmKxjAPQ1bU4sbbztH6hSYb4Je74XmRrL=w@mail.gmail.com>
From: Sasha Unknown <sasha2048@gmail.com>
Message-ID: <cc3f13e0-6f16-9893-7d6e-a4f9e6154c68@gmail.com>
Date: Thu, 18 Aug 2016 23:19:14 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
	Thunderbird/45.2.0
MIME-Version: 1.0
In-Reply-To: <CADn_AD-TpPkwh9LwmKxjAPQ1bU4sbbztH6hSYb4Je74XmRrL=w@mail.gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2a00:1450:4010:c07::234
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 20:19:23 -0000

Some time ago I workaround that issue with the following DIRTY HACK:

--- file.hh
+++ file.hh
@@ -178 +178 @@
-      return *new (yyas_<T> ()) T (t);
+      return *new (yyas_<T> ()) T (std::move((T&)t));

I'm not sure about stability of this "solution", probably it contains UB 
-- but it "worked" enough to test my prototype.


On 18.08.16 22:16, Min Wang wrote:
> HI
>
> Also
>
> http://lists.gnu.org/archive/html/bug-bison/2015-01/msg00066.html
>
> seems indicated bison does not support std::unique_ptr as a semantic values
>
>
> min
>
>
>
>
> On Thu, Aug 18, 2016 at 3:05 PM, Min Wang <mingewang@gmail.com> wrote:
>
>> HI
>> @kaz. thanks. I will check the %union later
>>
>> I'like to use the smart pointers ( std::unique_ptr) , but somehow I got
>> some compiler errors.
>>
>> here are some details:
>> e.g:
>>
>> using PROG_PTR = std::unique_ptr<PROG>;
>> ....
>>
>>
>> %type <PROG_PTR> PROG
>>
>> %type <ListExp_PTR> ListExp
>>
>> %type <Exp_PTR> Exp
>>
>> ...
>>
>>
>> PROG : ListExp      {
>>                     std::reverse( $1->begin(), $1->end() );
>>                     // store the result to filter_driver.prog
>>                     driver.store_ast( new Json_Filter( std::move($1) ) );
>>                     }
>> ;
>>
>> ListExp : Exp    {
>>                           ListExp_PTR tmp( new ListExp() ) ;
>>                           tmp->push_back( std::move($1) );
>>                           std::swap( $$, tmp );
>>                         }
>>
>> //some classes
>>
>> class PROG : public Visitable
>>
>> {
>>
>> public:
>>
>>      virtual ~PROG() {};
>>
>>
>>
>> };
>>
>> // real one here
>>
>> using ListExp_PTR = std::unique_ptr<ListExp>;
>>
>>
>>
>> class Json_Filter : public PROG
>>
>> {
>>
>> public:
>>
>>    ListExp_PTR listexp_;
>>
>>
>>
>>    Json_Filter(ListExp_PTR p1) : listexp_( std::move(p1) ) {}
>>
>>    ~Json_Filter() {}
>>
>>
>>
>> };
>>
>> // should not inherit vector here, put here just for testing now.
>> class ListExp : public Visitable, public std::vector<Exp_PTR>
>>
>> {
>>
>> public:
>>
>> };
>>
>>
>>
>> but I got those errors:
>> ....
>>
>> In file included from filter_parser.cpp:46:0:
>>
>> filter_parser.hh: In instantiation of ‘T& brc_filter::variant<S>::build(const
>> T&) [with T = std::unique_ptr<ListExp>; long unsigned int S = 8ul]’:
>> filter_parser.hh:241:12:   required from ‘void
>> brc_filter::variant<S>::copy(const self_type&) [with T =
>> std::unique_ptr<ListExp>; long unsigned int S = 8ul;
>> brc_filter::variant<S>::self_type = brc_filter::variant<8ul>]’
>> filter_parser.cpp:353:46:   required from here
>>
>> filter_parser.hh:184:37: error: use of deleted function
>> ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&)
>> [with _Tp = ListExp; _Dp = std::default_delete<ListExp>]’
>>         return *new (yyas_<T> ()) T (t);
>>
>>                                       ^
>>
>> In file included from /usr/include/c++/4.9/memory:81:0,
>>
>>                   from syntax.hh:6,
>>
>>                   from filter_parser.yy:46,
>>
>>                   from filter_parser.cpp:46:
>>
>> /usr/include/c++/4.9/bits/unique_ptr.h:356:7: note: declared here
>>
>>         unique_ptr(const unique_ptr&) = delete;
>>
>> ....
>>
>> the filter_parser.hh:184  is:
>>
>>      /// Instantiate a \a T in here from \a t.
>>
>>      template <typename T>
>>
>>      T&
>>
>>      build (const T& t)
>>
>>      {
>>
>>        YYASSERT (!yytypeid_);
>>
>>        YYASSERT (sizeof (T) <= S);
>>
>>        yytypeid_ = & typeid (T);
>>
>>        return *new (yyas_<T> ()) T (t);
>>
>>      }
>>
>>
>> seems the build function somehow is not right?
>>
>>
>> thanks
>>
>>
>> min
>>
>> On Thu, Aug 18, 2016 at 1:12 PM, Kaz Kylheku <kaz@kylheku.com> wrote:
>>
>>> On 18.08.2016 08:36, Min Wang wrote:
>>>
>>>> HI
>>>>
>>>> In bison 3.0.4, the  %destructor seems to be called even in the normal
>>>> parse
>>>>
>>> In your example program you are using "Variants" rather
>>> than %union. That's a very special C++-specific Bison feature.
>>>
>>> It seems that there is no reason to use %destructor if you're
>>> using variants. If any of the variants are pointers, they can
>>> just be smart pointers; they don't have to be low level pointers.
>>>
>>> Can you confirm whether %destructor is still called in the
>>> normal parse if instead of:
>>>
>>>    %type <PROG*> PROG
>>>    %type <ListExp*> ListExp
>>>
>>> you use
>>>
>>>    %union {
>>>      PROG *PROG;
>>>      ListExp *ListExp;
>>>    }
>>>
>>> That is to say, is this a issue specific to variants, or does it
>>> affect C++ parsers regardless of whether %union or variants
>>> are used?
>>>
>>> If under %union, %destructor is correctly called only during
>>> error recovery (the issue is absent) then just use %union,
>>> since all your semantic value types are pointers. Then be sure
>>> you have all the right delete calls in your grammar actions.
>>>
>>> If you use variants, it seems you can side-step the issue
>>> by not using pointers. If the values are smart pointers,
>>> then there is no problem, because a rule like:
>>>
>>>     foo : bar { $$ = $1; }
>>>
>>> will handle the transfer from $1 to $$ using the smart pointer
>>> assignment operator, allowing $1 to then be safely destroyed
>>> by its destructor.
>>>
>>> It does seem that you have discovered at least this bug,
>>> or deviation from documented behavior: when plain pointer types
>>> are used in variant declarations in a C++ parser, and %destructor
>>> is used to free them in all circumstances.
>>>
>>> So for instance, suppose that we use the type <char *>,
>>> and we have a %destructor which calls free. In a C parser,
>>> we might just have this:
>>>
>>>     foo : bar { $$ = $1; }  /* transfer ownership of pointer */
>>>
>>> But under C++ Bison with variants, we must do:
>>>
>>>     foo : bar { $$ = strdup($1); } /* $1 %destructor will kick in */
>>>
>>> Or perhaps this will work:
>>>
>>>     foo : bar { $$ = $1;
>>>                 $1 = NULL; } /* Spare $1 from jaws of %destructor */
>>>
>>>
>>>
>>>
>>
>> --
>> http://www.comrite.com
>>
>>
>>
>>
>



From MAILER-DAEMON Thu Aug 18 18:00:03 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1baVM3-0005uk-SF
	for mharc-bug-bison@gnu.org; Thu, 18 Aug 2016 18:00:03 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49925)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baVM0-0005uG-MP
	for bug-bison@gnu.org; Thu, 18 Aug 2016 18:00:02 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baVLx-0003O1-NB
	for bug-bison@gnu.org; Thu, 18 Aug 2016 17:59:59 -0400
Received: from mail-oi0-x22d.google.com ([2607:f8b0:4003:c06::22d]:33974)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mingewang@gmail.com>) id 1baVLx-0003Nw-FV
	for bug-bison@gnu.org; Thu, 18 Aug 2016 17:59:57 -0400
Received: by mail-oi0-x22d.google.com with SMTP id l203so40697334oib.1
	for <bug-bison@gnu.org>; Thu, 18 Aug 2016 14:59:57 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=WNe9UNooI8QIAiVENyO9+mzvUPzb2hypoSVpqq4mJ0Y=;
	b=iTpPvgIZdxIc7INVo2+M7EL+XvaBObCl5cFHxIMH3EhP6GgjyXhq5XFbKtZL6XmiP1
	GX6JBbdIEyXcpr0WDJDggy2mxGxoEtuLvKI9oTf+5mRPzTbtzEievaYpTk8XUvoR3RDg
	botNrjZYM3/q2MhzHyyISAqEfcy7jdQwUQGlYQfVi3LcuSU3JDvSiGS42yRzdY+BRkxI
	GE1k+LOkSakaIt7K5SpoO7rc0JnASf2M78exgzKl+54CnidIAdqHDh89y7ERqpefX0y5
	T7eDlDqbVq4uQovkEYSy9KLvPLPNYsPnbr0RgzJ6JckZh3iLn41AYB5iqay22FqG9GFe
	5hsA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=WNe9UNooI8QIAiVENyO9+mzvUPzb2hypoSVpqq4mJ0Y=;
	b=M9fTA9tQeEBl8IFjm13CnRXbujwOIlgNaVuKD3cR19pMgfJLvmiiCfGFRl5MK8+t+u
	pW0N0ozXR45CzpAhWhgd/rhjUhuKsnjDfJrVuVswF0sbvLKEn2qA3C8dNljH16XwvA64
	b/nKPpk2Ed7cZ8U75lInL53JNm708ATZGmWKQmpRFOlufhIdNSYl6seo8tMP9paqadON
	snHEy8IaBIuj+HPJIGSybMacG6Bko0g3ncITevQj5MxdpYpXgTgUi7o1iJCDiv+f+loY
	6/aeK5nhFFytk41y3EnFZ+U4J4E6iqiIrTlY0WCvRKu1e5sGD1QZjFJRLXIUGJ49HW49
	NMCA==
X-Gm-Message-State: AEkoouv4sqH09BvQuGh+EnUzAiiZVs97JLld0Th2TwP5YsPXwi0d7RaBYySspISTyaVnhY4BduDOVBPvMByzdA==
X-Received: by 10.157.1.163 with SMTP id e32mr2963379ote.175.1471557596929;
	Thu, 18 Aug 2016 14:59:56 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.182.215.138 with HTTP; Thu, 18 Aug 2016 14:59:56 -0700 (PDT)
In-Reply-To: <cc3f13e0-6f16-9893-7d6e-a4f9e6154c68@gmail.com>
References: <CADn_AD_=sVS-yVEbqu64vsLt96ezKuhaaXv9WwNd3asuE-Nv8w@mail.gmail.com>
	<6bb4323f6ccdae4f2473123188370bbd@mail.kylheku.com>
	<CADn_AD9ok=gA6cMb5dP6MUp8LfbkxD8Kc1Dduw_Tg9os4oanEQ@mail.gmail.com>
	<CADn_AD-TpPkwh9LwmKxjAPQ1bU4sbbztH6hSYb4Je74XmRrL=w@mail.gmail.com>
	<cc3f13e0-6f16-9893-7d6e-a4f9e6154c68@gmail.com>
From: Min Wang <mingewang@gmail.com>
Date: Thu, 18 Aug 2016 17:59:56 -0400
Message-ID: <CADn_AD_=Hq41eDefWGJva5uCpcsbnCSCRhf6zLR3tdiE=XK=2A@mail.gmail.com>
Subject: Re: bison 3.0.4 %destructor is c++ mode seems to be called even in
	the normal parse
To: Sasha Unknown <sasha2048@gmail.com>
Cc: bug-bison@gnu.org
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2607:f8b0:4003:c06::22d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
X-BeenThere: bug-bison@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Bug reports for Bison, the GNU parser generator" <bug-bison.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-bison/>
List-Post: <mailto:bug-bison@gnu.org>
List-Help: <mailto:bug-bison-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-bison>,
	<mailto:bug-bison-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Aug 2016 22:00:02 -0000

HI

@sasha, thanks!!  that worked.

Could someone add those suppprt for std::unique_ptr , that seems very
useful feature?



thanks


min



On Thu, Aug 18, 2016 at 4:19 PM, Sasha Unknown <sasha2048@gmail.com> wrote:

> Some time ago I workaround that issue with the following DIRTY HACK:
>
> --- file.hh
> +++ file.hh
> @@ -178 +178 @@
> -      return *new (yyas_<T> ()) T (t);
> +      return *new (yyas_<T> ()) T (std::move((T&)t));
>
> I'm not sure about stability of this "solution", probably it contains UB
> -- but it "worked" enough to test my prototype.
>
>
> On 18.08.16 22:16, Min Wang wrote:
>
>> HI
>>
>> Also
>>
>> http://lists.gnu.org/archive/html/bug-bison/2015-01/msg00066.html
>>
>> seems indicated bison does not support std::unique_ptr as a semantic
>> values
>>
>>
>> min
>>
>>
>>
>>
>> On Thu, Aug 18, 2016 at 3:05 PM, Min Wang <mingewang@gmail.com> wrote:
>>
>> HI
>>> @kaz. thanks. I will check the %union later
>>>
>>> I'like to use the smart pointers ( std::unique_ptr) , but somehow I got
>>> some compiler errors.
>>>
>>> here are some details:
>>> e.g:
>>>
>>> using PROG_PTR =3D std::unique_ptr<PROG>;
>>> ....
>>>
>>>
>>> %type <PROG_PTR> PROG
>>>
>>> %type <ListExp_PTR> ListExp
>>>
>>> %type <Exp_PTR> Exp
>>>
>>> ...
>>>
>>>
>>> PROG : ListExp      {
>>>                     std::reverse( $1->begin(), $1->end() );
>>>                     // store the result to filter_driver.prog
>>>                     driver.store_ast( new Json_Filter( std::move($1) ) =
);
>>>                     }
>>> ;
>>>
>>> ListExp : Exp    {
>>>                           ListExp_PTR tmp( new ListExp() ) ;
>>>                           tmp->push_back( std::move($1) );
>>>                           std::swap( $$, tmp );
>>>                         }
>>>
>>> //some classes
>>>
>>> class PROG : public Visitable
>>>
>>> {
>>>
>>> public:
>>>
>>>      virtual ~PROG() {};
>>>
>>>
>>>
>>> };
>>>
>>> // real one here
>>>
>>> using ListExp_PTR =3D std::unique_ptr<ListExp>;
>>>
>>>
>>>
>>> class Json_Filter : public PROG
>>>
>>> {
>>>
>>> public:
>>>
>>>    ListExp_PTR listexp_;
>>>
>>>
>>>
>>>    Json_Filter(ListExp_PTR p1) : listexp_( std::move(p1) ) {}
>>>
>>>    ~Json_Filter() {}
>>>
>>>
>>>
>>> };
>>>
>>> // should not inherit vector here, put here just for testing now.
>>> class ListExp : public Visitable, public std::vector<Exp_PTR>
>>>
>>> {
>>>
>>> public:
>>>
>>> };
>>>
>>>
>>>
>>> but I got those errors:
>>> ....
>>>
>>> In file included from filter_parser.cpp:46:0:
>>>
>>> filter_parser.hh: In instantiation of =E2=80=98T& brc_filter::variant<S=
>::build(
>>> const
>>> T&) [with T =3D std::unique_ptr<ListExp>; long unsigned int S =3D 8ul]=
=E2=80=99:
>>> filter_parser.hh:241:12:   required from =E2=80=98void
>>> brc_filter::variant<S>::copy(const self_type&) [with T =3D
>>> std::unique_ptr<ListExp>; long unsigned int S =3D 8ul;
>>> brc_filter::variant<S>::self_type =3D brc_filter::variant<8ul>]=E2=80=
=99
>>> filter_parser.cpp:353:46:   required from here
>>>
>>> filter_parser.hh:184:37: error: use of deleted function
>>> =E2=80=98std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_T=
p, _Dp>&)
>>> [with _Tp =3D ListExp; _Dp =3D std::default_delete<ListExp>]=E2=80=99
>>>         return *new (yyas_<T> ()) T (t);
>>>
>>>                                       ^
>>>
>>> In file included from /usr/include/c++/4.9/memory:81:0,
>>>
>>>                   from syntax.hh:6,
>>>
>>>                   from filter_parser.yy:46,
>>>
>>>                   from filter_parser.cpp:46:
>>>
>>> /usr/include/c++/4.9/bits/unique_ptr.h:356:7: note: declared here
>>>
>>>         unique_ptr(const unique_ptr&) =3D delete;
>>>
>>> ....
>>>
>>> the filter_parser.hh:184  is:
>>>
>>>      /// Instantiate a \a T in here from \a t.
>>>
>>>      template <typename T>
>>>
>>>      T&
>>>
>>>      build (const T& t)
>>>
>>>      {
>>>
>>>        YYASSERT (!yytypeid_);
>>>
>>>        YYASSERT (sizeof (T) <=3D S);
>>>
>>>        yytypeid_ =3D & typeid (T);
>>>
>>>        return *new (yyas_<T> ()) T (t);
>>>
>>>      }
>>>
>>>
>>> seems the build function somehow is not right?
>>>
>>>
>>> thanks
>>>
>>>
>>> min
>>>
>>> On Thu, Aug 18, 2016 at 1:12 PM, Kaz Kylheku <kaz@kylheku.com> wrote:
>>>
>>> On 18.08.2016 08:36, Min Wang wrote:
>>>>
>>>> HI
>>>>>
>>>>> In bison 3.0.4, the  %destructor seems to be called even in the norma=
l
>>>>> parse
>>>>>
>>>>> In your example program you are using "Variants" rather
>>>> than %union. That's a very special C++-specific Bison feature.
>>>>
>>>> It seems that there is no reason to use %destructor if you're
>>>> using variants. If any of the variants are pointers, they can
>>>> just be smart pointers; they don't have to be low level pointers.
>>>>
>>>> Can you confirm whether %destructor is still called in the
>>>> normal parse if instead of:
>>>>
>>>>    %type <PROG*> PROG
>>>>    %type <ListExp*> ListExp
>>>>
>>>> you use
>>>>
>>>>    %union {
>>>>      PROG *PROG;
>>>>      ListExp *ListExp;
>>>>    }
>>>>
>>>> That is to say, is this a issue specific to variants, or does it
>>>> affect C++ parsers regardless of whether %union or variants
>>>> are used?
>>>>
>>>> If under %union, %destructor is correctly called only during
>>>> error recovery (the issue is absent) then just use %union,
>>>> since all your semantic value types are pointers. Then be sure
>>>> you have all the right delete calls in your grammar actions.
>>>>
>>>> If you use variants, it seems you can side-step the issue
>>>> by not using pointers. If the values are smart pointers,
>>>> then there is no problem, because a rule like:
>>>>
>>>>     foo : bar { $$ =3D $1; }
>>>>
>>>> will handle the transfer from $1 to $$ using the smart pointer
>>>> assignment operator, allowing $1 to then be safely destroyed
>>>> by its destructor.
>>>>
>>>> It does seem that you have discovered at least this bug,
>>>> or deviation from documented behavior: when plain pointer types
>>>> are used in variant declarations in a C++ parser, and %destructor
>>>> is used to free them in all circumstances.
>>>>
>>>> So for instance, suppose that we use the type <char *>,
>>>> and we have a %destructor which calls free. In a C parser,
>>>> we might just have this:
>>>>
>>>>     foo : bar { $$ =3D $1; }  /* transfer ownership of pointer */
>>>>
>>>> But under C++ Bison with variants, we must do:
>>>>
>>>>     foo : bar { $$ =3D strdup($1); } /* $1 %destructor will kick in */
>>>>
>>>> Or perhaps this will work:
>>>>
>>>>     foo : bar { $$ =3D $1;
>>>>                 $1 =3D NULL; } /* Spare $1 from jaws of %destructor */
>>>>
>>>>
>>>>
>>>>
>>>>
>>> --
>>> http://www.comrite.com
>>>
>>>
>>>
>>>
>>>
>>
>
>


--=20
http://www.comrite.com

