c++: using macros around user types breaks when they include comma

We may generate code such as

    basic_symbol (typename Base::kind_type t, YY_RVREF (std::pair<int,int>) v);

which, of course, breaks, because YY_RVREF sees two arguments.  Let's
not play tricks with _VA_ARGS__, I'm unsure about it portability.
Anyway, I plan to change more things in this area.

Reported by Sébastien Villemot.
http://lists.gnu.org/archive/html/bug-bison/2018-11/msg00014.html

* data/variant.hh (b4_basic_symbol_constructor_declare)
(b4_basic_symbol_constructor_define): Don't use macro on user types.
* tests/types.at: Check that we support pairs.
This commit is contained in:
Akim Demaille
2018-11-20 19:28:12 +01:00
parent b72d654fa2
commit 4e510c69b1
3 changed files with 46 additions and 9 deletions

View File

@@ -270,6 +270,24 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
AT_VAL.build<std::string> ("two");],
[10, two])
# Test a regression where we passed user types (we can include
# commas) to a CPP macro.
AT_TEST([%skeleton "]b4_skel["
%define api.value.type variant],
[%token <std::pair<int, int>> '1';
%token <std::pair<std::string, std::string>> '2';],
['1' '2'
{
std::cout << $1.first << ':' << $1.second << ", "
<< $2.first << ':' << $2.second << '\n';
}],
["12"],
[if (res == '1')
AT_VAL.build (std::make_pair (10, 11));
else if (res == '2')
AT_VAL.build (std::make_pair<std::string, std::string> ("two", "deux"));],
[10:11, two:deux])
# Move-only types.
AT_TEST([%skeleton "]b4_skel["
%code requires { #include <memory> }