我对boost精神有一个问题,expression.The的原始代码更复杂,我给它做了一个小快照。此代码在调试模式下按预期工作,不发布,解析返回false,但应该返回true (我正在VisualStudio2019上测试它)
int main() {
namespace qi = boost::spirit::qi;
auto X19 = qi::lit(" ") | qi::lit(" 0.000000000000D+00");
auto i4 = qi::uint_;
string str = "1234 1234";
auto f = str.cbegin();
auto l = str.cend();
bool ret = qi::parse(f, l, ( i4 >> X19 >> i4 ));
}下一次快照在两种模式下都运行良好:
int main() {
namespace qi = boost::spirit::qi;
auto i4 = qi::uint_;
string str = "1234 1234";
auto f = str.cbegin();
auto l = str.cend();
bool ret = qi::parse(f, l, ( i4 >> (qi::lit(" ") | qi::lit(" 0.000000000000D+00")) >> i4 ));
cout << ret << endl;
return ret;
}我做错了什么,用这种方式划分长表情?谢谢
发布于 2021-10-04 14:56:12
你不由自主地跑进了悬挂的临时陷阱,用圣灵的Proto表情。简短的规则是:
不要在精灵表达式中使用
auto
您的程序展示了未定义行为:请参阅在编译器资源管理器上直播

解决方案涉及BOOST_SPIRIT_AUTO或qi::copy (在最近发布的boost版本之前,它们以前只作为boost::proto::deep_copy使用)。
固定
住在Coliru
#include <boost/spirit/include/qi.hpp>
int main() {
namespace qi = boost::spirit::qi;
auto i4 = qi::copy(qi::uint_);
auto X19 = qi::copy( //
qi::lit(" ") //
| qi::lit(" 0.000000000000D+00")//
);
std::string str = "1234 1234";
auto f = str.cbegin(), l = str.cend();
bool ret = qi::parse(f, l, (i4 >> X19 >> i4));
std::cout << std::boolalpha << ret << "\n";
}打印
true奖金
https://stackoverflow.com/questions/69437727
复制相似问题