-
Notifications
You must be signed in to change notification settings - Fork 100
Description
This was originally reported to the bug-bison
mailing list- https://lists.gnu.org/archive/html/bug-bison/2025-07/msg00003.html
I'm copying the bug report here because it's easier to read and follow
The api.value.automove
directive doesn't honor an explicit false
setting.
// test_automove.y
%skeleton "lalr1.cc"
%require "3.8"
%language "c++"
%define api.value.automove false
%token <int> VAL
%nterm <int> x
%%
x: VAL
Generate C++ parser test_automove.cpp
bison -o test_automove.cpp test_automove.y
Generated code has std::move
applied to $1
via YY_MOVE
grep -B2 "yylhs.value.int" test_automove.cpp
case 2: // x: VAL
#line 14 "test_automove.y"
{ (yylhs.value.int) = YY_MOVE ((yystack_[0].value.int)); }
bison --version
bison (GNU Bison) 3.8.2
The problem is in skeletons/lalr1.cc
where b4_percent_define_ifdef
applies YY_MOVE
as long as api.value.automove
is defined without considering its value
The default value of api.value.automove
is false
- omitting the directive does prevent YY_MOVE
from being applied
m4_define([b4_rhs_value],
[b4_percent_define_ifdef([api.value.automove],
[YY_MOVE (_b4_rhs_value($@))],
[_b4_rhs_value($@)])])
b4_percent_define_ifdef
is defined in skeletons/bison.m4
# _b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
# ------------------------------------------------------
# If the %define variable VARIABLE is defined, expand IF-TRUE, else expand
# IF-FALSE. Don't record usage of VARIABLE.
I'll send a fix for lalr1.cc
shortly to bison-patches
that looks like this
111a112,114
> # api.value.automove boolean default value false
> b4_percent_define_default([[api.value.automove]], [[false]])
>
113,115c116,118
< [b4_percent_define_ifdef([api.value.automove],
< [YY_MOVE (_b4_rhs_value($@))],
< [_b4_rhs_value($@)])])
---
> [b4_percent_define_flag_if([api.value.automove],
> [YY_MOVE (_b4_rhs_value($@))],
> [_b4_rhs_value($@)])])