X3 spirit, semantic action makes compilation fail: The attribute does not have the expected size

This code does not compile (gcc 5.3.1 + boost 1.60):

#include <boost/spirit/home/x3.hpp> namespace x3 = boost::spirit::x3; template <typename T> void parse(T begin, T end) { auto dest = x3::lit('[') >> x3::int_ >> ';' >> x3::int_ >> ']'; auto on_portal = [&](auto& ctx) {}; auto portal = (x3::char_('P') >> -dest)[on_portal]; auto tiles = +portal; x3::phrase_parse(begin, end, tiles, x3::eol); } int main() { std::string x; parse(x.begin(), x.end()); } 

Unable to execute static statement:

 error: static assertion failed: Attribute does not have the expected size. 

Thanks to wandbox, I also tried to increase the level of 1.61 and clang, both give the same results.

If I delete the semantic action attached to the portal , it compiles fine; the same thing happens if I change dest to:

 auto dest = x3::lit('[') >> x3::int_ >> ']'; 

Any help would be greatly appreciated. TIA.

+8
c ++ boost-spirit boost-spirit-x3
source share
1 answer

This is also surprising, I would report it on the mailing list (or in trackers) as a potential error.

Meanwhile, you can "fix" it by specifying the attribute type for dest :

Live on coliru

 #include <boost/fusion/adapted/std_tuple.hpp> #include <boost/spirit/home/x3.hpp> #include <iostream> namespace x3 = boost::spirit::x3; template <typename T> void parse(T begin, T end) { auto dest = x3::rule<struct dest_type, std::tuple<int, int> > {} = '[' >> x3::int_ >> ';' >> x3::int_ >> ']'; auto on_portal = [&](auto& ctx) { int a, b; if (auto tup = x3::_attr(ctx)) { std::tie(a, b) = *tup; std::cout << "Parsed [" << a << ", " << b << "]\n"; } }; auto portal = ('P' >> -dest)[on_portal]; auto tiles = +portal; x3::phrase_parse(begin, end, tiles, x3::eol); } int main() { std::string x = "P[1;2]P[3;4]P[5;6]"; parse(x.begin(), x.end()); } 

Print

 Parsed [1, 2] Parsed [3, 4] Parsed [5, 6] 

NOTE I changed char_('P') to just lit('P') because I did not want to complicate the pattern processing the character in the attribute. Perhaps you still did not want to have it in the exposed attribute.

+4
source share

All Articles