From cd6b96276be613f2d313873046f92389a78c327e Mon Sep 17 00:00:00 2001 From: gabewillen Date: Mon, 23 Feb 2026 17:15:12 -0600 Subject: [PATCH] Fix issue #171 wildcard event double invocation --- include/boost/sml.hpp | 2 ++ test/ft/CMakeLists.txt | 3 +++ test/ft/issue_171.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 test/ft/issue_171.cpp diff --git a/include/boost/sml.hpp b/include/boost/sml.hpp index 7065e66e..ddb0e191 100644 --- a/include/boost/sml.hpp +++ b/include/boost/sml.hpp @@ -1477,6 +1477,8 @@ struct get_event_mapping_impl_helper, TMappings> template struct get_event_mapping_impl_helper, TMappings> : decltype(get_event_mapping_impl>((TMappings *)0)) {}; +template +struct get_event_mapping_impl_helper : decltype(get_event_mapping_impl((TMappings *)0)) {}; template using get_event_mapping_t = get_event_mapping_impl_helper; } // namespace back diff --git a/test/ft/CMakeLists.txt b/test/ft/CMakeLists.txt index 6c1750b9..feaf4d43 100644 --- a/test/ft/CMakeLists.txt +++ b/test/ft/CMakeLists.txt @@ -48,6 +48,9 @@ add_test(test_fwd test_fwd) add_executable(test_history history.cpp) add_test(test_history test_history) +add_executable(test_issue_171 issue_171.cpp) +add_test(test_issue_171 test_issue_171) + add_executable(test_issue_253 issue_253.cpp) add_test(test_issue_253 test_issue_253) diff --git a/test/ft/issue_171.cpp b/test/ft/issue_171.cpp new file mode 100644 index 00000000..52abe7f9 --- /dev/null +++ b/test/ft/issue_171.cpp @@ -0,0 +1,44 @@ +// +// Copyright (c) 2016-2020 Kris Jusiak (kris at jusiak dot net) +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#include + +namespace sml = boost::sml; + +test issue_171_event_any_is_not_fired_twice = [] { + struct e1 {}; + + struct issue_171_counters { + int init_calls = 0; + int wildcard_calls = 0; + }; + + struct issue_171_transitions { + auto operator()() const noexcept { + using namespace sml; + const auto issue_171_idle = sml::state; + const auto issue_171_s1 = sml::state; + const auto issue_171_s2 = sml::state; + + // clang-format off + return make_transition_table( + *issue_171_idle / [](issue_171_counters& counters) { ++counters.init_calls; } = issue_171_s1 + , issue_171_s1 + event<_> / [](issue_171_counters& counters) { ++counters.wildcard_calls; } + , issue_171_s2 + event / [] {} + ); + // clang-format on + } + }; + + issue_171_counters counters{}; + sml::sm sm{counters}; + + sm.process_event(e1{}); + + expect(1 == counters.init_calls); + expect(1 == counters.wildcard_calls); +};