sml
sml copied to clipboard
Crash in guard when dependency referenced by const vs non-const
Expected Behavior
for non-const dependency both const and non-const access is valid.
Actual Behavior
only non-const is valid while const result in nullptr and crash.
Steps to Reproduce the Problem
crash which can be fixed by replacing Dep const*
with Dep*
in line 26.
I might be wrong, but from what I understand, sml captures dependencies and matches their type with all modifiers. If not matched, it will pass garbage to your actions/guards/etc.
For example, this fixes your example too (constness now match):
const Dep dep;
sml::sm<events> sm(&dep);
And if you do this, it will happily compile but crash by passing garbage to your guard:
int i = 0;
sml::sm<events> sm(&i);
AFAIK, sml has the check to detect non-captured dependencies but it seems to work only for references:
In instantiation of 'boost::ext::sml::v1_1_5::aux::pool_type_impl<T&, typename boost::ext::sml::v1_1_5::aux::enable_if<(decltype (test_is_constructible<T>(0))::value && decltype (test_is_constructible<T, T>(0))::value), void>::type>::pool_type_impl(TObject)
[with TObject = boost::ext::sml::v1_1_5::aux::missing_ctor_parameter<{anonymous}::Dep2>; T = {anonymous}::Dep2;
typename boost::ext::sml::v1_1_5::aux::enable_if<(decltype (test_is_constructible<T>(0))::value && decltype (test_is_constructible<T, T>(0))::value), void>::type = void]':
I would assume 2 things:
- it should check pointers as well.
- it should follow native C++ conversion rules which implicitly converts from non-const to const.