c++: fix token constructors for types with commas

Bitten by macros, again.
See 680b715518.

* data/variant.hh (_b4_symbol_constructor_declare)
(_b4_symbol_constructor_define): Do not use user types, which can
include commas as in `std::pair<int, int>`, to macros.

* tests/local.at: Adjust the lex related macros to support the
case of token constructors.
* tests/types.at: Also check token constructors on types with commas.
This commit is contained in:
Akim Demaille
2018-12-18 13:22:03 +01:00
parent 93cc1fa6e8
commit 98d199ccc8
3 changed files with 75 additions and 22 deletions

View File

@@ -304,7 +304,29 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
else if (res == '2')
]AT_VAL[.emplace <std::pair<int, int>> (21, 22);]],
[10, 21, 22],
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])])
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])
# Token constructors on move-only types, and types with commas.
AT_TEST([%skeleton "]b4_skel["
%code requires { #include <memory> }
%define api.value.type variant
%define api.token.constructor],
[[%token <std::unique_ptr<int>> ONE;
%token <std::pair<int, int>> TWO;
%token EOI 0;]],
[ONE TWO { std::cout << *$1 << ", "
<< $2.first << ", "
<< $2.second << '\n'; }],
["12"],
[[if (res == '1')
return yy::parser::make_ONE (std::make_unique<int> (10));
else if (res == '2')
return yy::parser::make_TWO (std::make_pair<int, int> (21, 22));
else
return yy::parser::make_EOI ()]],
[10, 21, 22],
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])
])
])