2

It seems that adding a semantic action can break attribute compatibility. The following simple example works and compiles as expected:

auto pair_rule = x3::rule<class·pair_rule, std::pair<std::string, std::string>>()
    = x3::alnum >> '=' >> x3::alnum;
auto combined = pair_rule | x3::alnum;

Now, when I add a semantic action to the pair_rule in combined:

auto action = [&](auto& ctx) {}; 
auto pair_rule = x3::rule<class pair_rule, std::pair<std::string, std::string>>()
    = x3::alnum >> '=' >> x3::alnum;
auto combined = pair_rule[action] | x3::alnum;

The compiler complains about moving incompatible types

boost_1_62_0/boost/spirit/home/x3/support/traits/move_to.hpp:62:18: note:   mismatched types ‘const std::pair<_T1, _T2>’ and ‘std::remove_reference<const char&>::type {aka const char}’
         dest = std::move(src);

However, when adding another semantic action to one of the alnum parsers in pair_rule, the code compiles again:

auto action = [&](auto& ctx) {}; 
auto pair_rule = x3::rule<class pair_rule, std::pair<std::string, std::string>>()
    = x3::alnum >> '=' >> x3::alnum[action];
auto combined = pair_rule[action] | x3::alnum;

Why does the semantic action break the attribute compatibility, and how does the additional semantic action "fix" it?

haphi
  • 74
  • 4
  • 1
    You can find some explanation here http://boost-spirit.com/home/articles/attribute_handling/attribute-propagation-and-attribute-compatibility/ about why semantic action can break attribute compatibility. I did not understand it completely though. – Arunmu Nov 12 '16 at 22:23

0 Answers0