[Boost::ext].SML Mingw64 GCC Debug构建下守卫触发段错误
代码
#include <sml.hpp> namespace { struct Event { bool pressed; }; struct Guard1 { [[nodiscard]] bool operator()(const Event& e) const { return e.pressed; } } guard1; struct Guard2 { [[nodiscard]] bool operator()(const Event& e) const { return true; } } guard2; struct Guard3 { [[nodiscard]] bool operator()(const Event& e) const { return true; } } guard3; }// namespace namespace sml = boost::sml; struct Fsm { struct State {}; auto operator()() const { using namespace boost::sml; return make_transition_table( // clang-format off *state<State> + event<Event>[guard1 && guard2 && guard3] = state<State> // clang-format on ); } }; int main() { boost::sml::sm<Fsm> fsm{}; fsm.process_event(Event{}); }
预期行为
程序正常运行,无段错误。
实际行为
在Guard1中访问Event实例的pressed字段时触发段错误,进程退出码为-1073741819 (0xC0000005)。
调试观测结果:Event对象地址在front::transition::execute中访问正常,进入front::call::execute后地址被损坏;移除任意一个守卫条件后程序可正常运行。

Event地址在front::transition::execute中状态正常:
进入front::call::execute后Event地址损坏:
复现步骤
- 使用MSYS2提供的GCC编译器,版本为
gcc.exe (Rev2, Built by MSYS2 project) 12.1.0 - 添加编译参数
-g -std=gnu++20构建Debug版本程序 - 运行构建出的程序即可触发问题
环境规格
- [Boost::ext].SML版本:1.1.4、1.1.5
- 运行平台:Windows,编译环境为MSYS2 mingw-w64-x86_64-gcc 12.1.0
内容的提问来源于stack exchange,提问作者Nicolas
相关产品推荐
相关产品推荐

