此代码不编译(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());
}它在静态断言中失败:
error: static assertion failed: Attribute does not have the expected size.感谢wandbox,我还尝试了boost 1.61和clang,两者产生了相同的结果。
如果删除附加到portal的语义操作,它会编译得很好;如果我将dest更改为:
auto dest = x3::lit('[') >> x3::int_ >> ']';任何帮助都将不胜感激。蒂娅。
发布于 2022-09-07 16:02:43
该bug在Boost 1.77 (由PR665 X3:可选解析器不是直通解析器修复)中得到修正。
在这种情况下,修复应用于属性较少的地方,但实际上并非如此,这可能会让人感到困惑,语义操作会为您创建一个临时属性,使您能够通过上下文进行访问(即使您真的不需要它)。
https://stackoverflow.com/questions/38213729
复制相似问题