You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

[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中状态正常:
transition阶段调试截图

进入front::call::execute后Event地址损坏:
call阶段调试截图

复现步骤

  • 使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 22:36:24