From MAILER-DAEMON Thu Jun 29 10:59:51 2017
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1dQav9-0008DM-Ap
	for mharc-bug-bison@gnu.org; Thu, 29 Jun 2017 10:59:51 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:58880)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <piomar123@gmail.com>) id 1dQZut-0005fo-FO
	for bug-bison@gnu.org; Thu, 29 Jun 2017 09:55:32 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <piomar123@gmail.com>) id 1dQZus-0000QB-Hu
	for bug-bison@gnu.org; Thu, 29 Jun 2017 09:55:31 -0400
Received: from mail-oi0-x22a.google.com ([2607:f8b0:4003:c06::22a]:36387)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <piomar123@gmail.com>) id 1dQZus-0000Ol-Cy
	for bug-bison@gnu.org; Thu, 29 Jun 2017 09:55:30 -0400
Received: by mail-oi0-x22a.google.com with SMTP id p187so66882718oif.3
	for <bug-bison@gnu.org>; Thu, 29 Jun 2017 06:55:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=mime-version:from:date:message-id:subject:to;
	bh=RxNggKXBbnx/Lc3r/KGPYHBuUUc2Y6DE54ApN8MdNlY=;
	b=bxGbNteBkSCEEqwjE9eqPB7azqVVFFfJ56Ahf0G3YL75/IzUC4vcdxTJ7kf9KAYPzs
	fgeii4Oed/EPlzd29Qd1qh3kXXjfhUYXNF42wkANCrA68PCTynnGF3pz83AC81avV4RV
	d4ZbD/DeVZEaN8Okj4gVjsc7ANie707iiPVHaEaib9axcvcf8SoGGkl6zPzZ7N7UVYTh
	oD6EfqtUA9carCQFVA2rWg5WRnI2H2NpYuSuffv/pIfr3IESL3OQdQRWxzcAB9i87egu
	KVOJfqa6dNktu/iZgAe11TXaIvv6LyXagk/5lEtW6yT0FoJmuuIlffhNbWnEBBawjZGm
	qN8A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
	bh=RxNggKXBbnx/Lc3r/KGPYHBuUUc2Y6DE54ApN8MdNlY=;
	b=o0lMObepnbFc+t9mFk9mFqPOO29aQfD4QkO0epHrs27cHNXjdHB8FWoTPsnJeiKEtz
	pySJkCk15C566fafqrvqqkekKHWP/hHFQRhkxHV04gqbu1u8ZFBV+OytiFaFSYW4XiWu
	41k+cYFjXHiV7NKQFEhslFawPmAraTHuVW9BA3SremX9KwmeMi6VN4vJzCm1jqhSpb2t
	hqmiW7zS8hxtLHus6tHn6lJKdiCDwgQcB/XgvSjeiimeidNaq7CF14avcOlO5+WXbmva
	nbwq7Q0gGM0NdzwNN5R/lDsOJdUr40WVBUHcvPuFNlopPjByGJqDOJTqcQGETPmeProt
	Apyw==
X-Gm-Message-State: AKS2vOxY0way5/KknBnGpkAl11MXlEmDZ87m8GpbrnOE4kKuDjRPdAMF
	G798YLuS2CLFdPVsMp/fa+VqKXM/Ng==
X-Received: by 10.202.208.130 with SMTP id j2mr9783963oiy.150.1498744527338;
	Thu, 29 Jun 2017 06:55:27 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.202.49.84 with HTTP; Thu, 29 Jun 2017 06:55:06 -0700 (PDT)
From: =?UTF-8?Q?Piotr_Marci=C5=84czyk?= <piomar123@gmail.com>
Date: Thu, 29 Jun 2017 15:55:06 +0200
Message-ID: <CAFV=A5Roy8Hu2A6G8XOoFUCfJMqETGOoZoJc3B6-k6fwtLczOg@mail.gmail.com>
Subject: Bison C++ mid-rule value lost with variants
To: bug-bison@gnu.org
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 2607:f8b0:4003:c06::22a
X-Mailman-Approved-At: Thu, 29 Jun 2017 10:59:50 -0400
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, 29 Jun 2017 13:55:32 -0000

I supposedly found a bug in lalr1.cc skeleton with variant semantic type.
When using mid-rule action { $<type>$ =3D value; } to return a value that
will be used in further semantic actions, it appears that the value on
stack becomes zero. Tested with Bison version 3.0.4.

Link to a minimal working example:
https://pastebin.com/bwsTSWNU

Link to StackOverflow question about it:
https://stackoverflow.com/q/44811550/1538920

=E2=80=8BBest regards,

Piotr Marci=C5=84czyk

From MAILER-DAEMON Thu Jun 29 14:08:12 2017
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1dQdrP-0006bx-RM
	for mharc-bug-bison@gnu.org; Thu, 29 Jun 2017 14:08:11 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:36555)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kaz@kylheku.com>) id 1dQdrM-0006a1-Tx
	for bug-bison@gnu.org; Thu, 29 Jun 2017 14:08:10 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <kaz@kylheku.com>) id 1dQdrJ-0004bq-OQ
	for bug-bison@gnu.org; Thu, 29 Jun 2017 14:08:08 -0400
Received: from smtp-out-so.shaw.ca ([64.59.136.139]:53330)
	by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
	(Exim 4.71) (envelope-from <kaz@kylheku.com>) id 1dQdrJ-0004XO-J1
	for bug-bison@gnu.org; Thu, 29 Jun 2017 14:08:05 -0400
Received: from kylheku.com ([70.79.163.252]) by shaw.ca with SMTP
	id Qdr5dRtFWyd2DQdr7d3gFy; Thu, 29 Jun 2017 12:07:53 -0600
X-Authority-Analysis: v=2.2 cv=F5wnTupN c=1 sm=1 tr=0
	a=95A0EdhkF1LMGt25d7h1IQ==:117 a=95A0EdhkF1LMGt25d7h1IQ==:17
	a=IkcTkHD0fZMA:10 a=SMorJkV_YP8A:10 a=LWSFodeU3zMA:10
	a=Uqouuy26S-PyaMjQCEUA:9 a=H_sS82qebrGlJD3x:21 a=0qqMolxe6mMlVMX6:21
	a=QEXdDO2ut3YA:10
Received: from www-data by kylheku.com with local (Exim 4.72)
	(envelope-from <kaz@kylheku.com>)
	id 1dQdr4-00045C-Gp; Thu, 29 Jun 2017 11:07:50 -0700
To: =?UTF-8?Q?Piotr_Marci=C5=84czyk?= <piomar123@gmail.com>
Subject: Re: Bison C++ mid-rule value lost with variants
X-PHP-Originating-Script: 501:rcmail.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8;
 format=flowed
Content-Transfer-Encoding: 8bit
Date: Thu, 29 Jun 2017 11:07:50 -0700
From: Kaz Kylheku <kaz@kylheku.com>
Cc: bug-bison@gnu.org
In-Reply-To: <CAFV=A5Roy8Hu2A6G8XOoFUCfJMqETGOoZoJc3B6-k6fwtLczOg@mail.gmail.com>
References: <CAFV=A5Roy8Hu2A6G8XOoFUCfJMqETGOoZoJc3B6-k6fwtLczOg@mail.gmail.com>
Message-ID: <5d58c7014e22f71880ec6ca8b078d3c8@mail.kylheku.com>
X-Sender: kaz@kylheku.com
User-Agent: Roundcube Webmail/0.9.2
X-CMAE-Envelope: MS4wfKcEUytWMjOoF/hlysiqCobZyUHTH3zzb+8lsldSy806s4lkkFjzuvmV+bFjevgww6k8XvtUkb+wz0hVhjDGnhOnUXPMW1aHWpScTrEmjNgApHME4eGn
	DC3DEGFkjqSIh7kwzoUXNxRfbokLSg+sRPn3p3yxfencdal/PnpT/bh87kU1BgyEfdoD77w85h6RdQ==
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy]
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, 29 Jun 2017 18:08:11 -0000

On 29.06.2017 06:55, Piotr Marcińczyk wrote:
> I supposedly found a bug in lalr1.cc skeleton with variant semantic 
> type.
> When using mid-rule action { $<type>$ = value; } to return a value that
> will be used in further semantic actions, it appears that the value on
> stack becomes zero. Tested with Bison version 3.0.4.

You probably need your code to work with Bison installations
that don't have a fix for this (which is all of them, currently,
except maybe yours).

Could the workaround be as simple as:

    /* plain old local variable, injected into yyparse */

    { int whatever = 42; } + NUM { std::cout << whatever << std::endl; }

Also, you can have a scratch space in your parser structure
for carrying a value from one mid-rule action to another.

    /* assumes %parse-param{your_parser_type *parser} */

    { parser->stash = 42; } + NUM { std::cout << parser->stash << 
std::endl: }

I've done this latter sort of of thing.

The parser structure is basically your "this" object in the entire
parse job, and yyparse is its "method". :)

Cheers ...



From MAILER-DAEMON Thu Jun 29 14:38:33 2017
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1dQeKn-00009f-92
	for mharc-bug-bison@gnu.org; Thu, 29 Jun 2017 14:38:33 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:44222)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <piomar123@gmail.com>) id 1dQeKj-00008G-Kk
	for bug-bison@gnu.org; Thu, 29 Jun 2017 14:38:31 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <piomar123@gmail.com>) id 1dQeKi-0002cd-EF
	for bug-bison@gnu.org; Thu, 29 Jun 2017 14:38:29 -0400
Received: from mail-oi0-x22d.google.com ([2607:f8b0:4003:c06::22d]:34954)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <piomar123@gmail.com>) id 1dQeKi-0002cL-6Q
	for bug-bison@gnu.org; Thu, 29 Jun 2017 14:38:28 -0400
Received: by mail-oi0-x22d.google.com with SMTP id c189so73974887oia.2
	for <bug-bison@gnu.org>; Thu, 29 Jun 2017 11:38:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=RnIIALcbXUu0q+HTFVt2YJYop76DDwK4v4cbQjrRRx8=;
	b=d8ZG3uwJksj1D4+PUe4svZWRhKNldDwQYgcr+0KFjSjSIHPENdfyU18zhWQne3zR8C
	4cTY5HgerkMj4FXX0D3iYOAUlWcIBJS45EC1dSV5rCpiX++pdPEkzj1Ub3xwzUPhIB+G
	AWKZ/gbUbX/sWhKs1LxLxE/ghn1scWUfI1fX0u32nb8ieBLiJVhq1OdMTHTouJuZv7ol
	Kpg5Pr5pN8u0gZmCDLX6bowX7QpFEa7oGaX2escm1pPPZtmFfjv+VnC1tuIPNhp2KpQ5
	jM2qMi6NnGQeRP96mOI0HcJGzU7+bvqU3LZbqiF6eputEM39SR/iZ0A/j3mGUey/wRfh
	k14Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=RnIIALcbXUu0q+HTFVt2YJYop76DDwK4v4cbQjrRRx8=;
	b=PXI8Cm6O2PvHWFj2BGe8GSXAMgxaGS7STAYp7SDR65kFmpYrBrVsrfk7Ldu085fUoO
	trj29RGLFEBoxWXo7Zl+TbEE5UPyIw5oEoM4GJbXANYXMqLMRb/K02n+YWkiRv1LHfWd
	0FUBF/iByergo7nj9zjcuUlThVWiIw5utmIENbhjMEttSQUuWqa8tzX1I0WzgfIqOplr
	KMcu/fnqg9wyXCRE9jVhCiWmneeCLY1kOdTFqE82Ag/uxCY4RKkYmv8qpHYXUj8zDdNA
	nclZLdqMNQfQdOH2GF8j2CADkxcv1Tyt4o5wuSQak4fRjvbMGIUsD8gOKfN6NW9jGd7n
	rQ3A==
X-Gm-Message-State: AKS2vOzYCCq2QBtb8SKA6r74GkT+WTDrg2fnknKvLWRD8sj2mxSn88NP
	b+rmbm2KwrqztDgSa/1VBEE2/jPUyg==
X-Received: by 10.202.81.202 with SMTP id f193mr12156759oib.178.1498761507355; 
	Thu, 29 Jun 2017 11:38:27 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.202.49.84 with HTTP; Thu, 29 Jun 2017 11:38:06 -0700 (PDT)
In-Reply-To: <5d58c7014e22f71880ec6ca8b078d3c8@mail.kylheku.com>
References: <CAFV=A5Roy8Hu2A6G8XOoFUCfJMqETGOoZoJc3B6-k6fwtLczOg@mail.gmail.com>
	<5d58c7014e22f71880ec6ca8b078d3c8@mail.kylheku.com>
From: =?UTF-8?Q?Piotr_Marci=C5=84czyk?= <piomar123@gmail.com>
Date: Thu, 29 Jun 2017 20:38:06 +0200
Message-ID: <CAFV=A5QxfxsNO27tqU05gWxbex10S3zcs06xX+B7nJ1cyGp0VQ@mail.gmail.com>
Subject: Re: Bison C++ mid-rule value lost with variants
To: Kaz Kylheku <kaz@kylheku.com>
Cc: bug-bison@gnu.org
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
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, 29 Jun 2017 18:38:31 -0000

Thanks for the workaround. Actually, I used marker tokens with actions
getting value from stack before the rule, e.g.:

%type <int> AnswerToLifeMarker

expr: expr AnswerToLifeMarker + NUM { std::cout << $2 << std::endl; };

AnswerToLifeMarker: { usePreviousExpr($<int>0); $$ =3D 42; };

=E2=80=8BThat's because I need a way to create and store labels for later j=
umps
between statements=E2=80=8B in generated code. So one global value is not
sufficient. I would need a separate stack for that - I tried this approach
and the code seemed more error prone and less maintainable.


=E2=80=8BBest regards,

      Piotr Marci=C5=84czyk

2017-06-29 20:07 GMT+02:00 Kaz Kylheku <kaz@kylheku.com>:

> On 29.06.2017 06:55, Piotr Marci=C5=84czyk wrote:
>
>> I supposedly found a bug in lalr1.cc skeleton with variant semantic type=
.
>> When using mid-rule action { $<type>$ =3D value; } to return a value tha=
t
>> will be used in further semantic actions, it appears that the value on
>> stack becomes zero. Tested with Bison version 3.0.4.
>>
>
> You probably need your code to work with Bison installations
> that don't have a fix for this (which is all of them, currently,
> except maybe yours).
>
> Could the workaround be as simple as:
>
>    /* plain old local variable, injected into yyparse */
>
>    { int whatever =3D 42; } + NUM { std::cout << whatever << std::endl; }
>
> Also, you can have a scratch space in your parser structure
> for carrying a value from one mid-rule action to another.
>
>    /* assumes %parse-param{your_parser_type *parser} */
>
>    { parser->stash =3D 42; } + NUM { std::cout << parser->stash <<
> std::endl: }
>
> I've done this latter sort of of thing.
>
> The parser structure is basically your "this" object in the entire
> parse job, and yyparse is its "method". :)
>
> Cheers ...
>
>

From MAILER-DAEMON Thu Jun 29 15:35:40 2017
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1dQfE4-00013k-K6
	for mharc-bug-bison@gnu.org; Thu, 29 Jun 2017 15:35:40 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:56585)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <haberg-1@telia.com>) id 1dQfE1-00012E-UG
	for bug-bison@gnu.org; Thu, 29 Jun 2017 15:35:38 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <haberg-1@telia.com>) id 1dQfDx-0002IA-Te
	for bug-bison@gnu.org; Thu, 29 Jun 2017 15:35:37 -0400
Received: from v-smtpout1.han.skanova.net ([81.236.60.154]:54500)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <haberg-1@telia.com>) id 1dQfDx-0002GR-MU
	for bug-bison@gnu.org; Thu, 29 Jun 2017 15:35:33 -0400
Received: from [10.0.1.4] ([90.227.203.185]) by cmsmtp with SMTP
	id QfDudhz9fPPY2QfDudXfF3; Thu, 29 Jun 2017 21:35:31 +0200
Content-Type: text/plain; charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\))
Subject: Re: Bison C++ mid-rule value lost with variants
From: =?utf-8?Q?Hans_=C3=85berg?= <haberg-1@telia.com>
In-Reply-To: <CAFV=A5Roy8Hu2A6G8XOoFUCfJMqETGOoZoJc3B6-k6fwtLczOg@mail.gmail.com>
Date: Thu, 29 Jun 2017 21:35:29 +0200
Cc: bug-bison@gnu.org
Content-Transfer-Encoding: quoted-printable
Message-Id: <C44980D6-D2FB-45F0-8740-1C3239CADE9A@telia.com>
References: <CAFV=A5Roy8Hu2A6G8XOoFUCfJMqETGOoZoJc3B6-k6fwtLczOg@mail.gmail.com>
To: =?utf-8?Q?Piotr_Marci=C5=84czyk?= <piomar123@gmail.com>
X-Mailer: Apple Mail (2.3273)
X-CMAE-Envelope: MS4wfHq8rLX4Z6EjyU+nzkK+9AA2xhTsa1PNwg4egoOro7LZ//QwRJLxVkgKTWJPJW0/tS3xs37sNgCC+ulMtAEKDq6/u6J0uFlOW/WnG/rYvcFfNq9tT0RW
	6FgxmFcPL216G3GY6YzL16disN0sH3+cptIX7DZ1YesD4RcATYGKLefIWjxb7mSn1OTZSsJci/9MuQ==
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (barebone)
	[generic] [fuzzy]
X-Received-From: 81.236.60.154
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, 29 Jun 2017 19:35:39 -0000


> On 29 Jun 2017, at 15:55, Piotr Marci=C5=84czyk <piomar123@gmail.com> =
wrote:
>=20
> I supposedly found a bug in lalr1.cc skeleton with variant semantic =
type.

You might check if std::variant, of C++17, can be used instead. Cf.
  http://en.cppreference.com/w/cpp/utility/variant

> When using mid-rule action { $<type>$ =3D value; } to return a value =
that
> will be used in further semantic actions, it appears that the value on
> stack becomes zero. Tested with Bison version 3.0.4.

This happens also if moved out to a separate rule, perhaps overwritten =
by the token semantic value. So it does not look safe for use.



