sml icon indicating copy to clipboard operation
sml copied to clipboard

Crash in guard when dependency referenced by const vs non-const

Open cppden opened this issue 3 years ago • 2 comments

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.

cppden avatar Jan 13 '22 12:01 cppden

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);

ukreator avatar Mar 24 '22 05:03 ukreator

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:

  1. it should check pointers as well.
  2. it should follow native C++ conversion rules which implicitly converts from non-const to const.

cppden avatar Mar 31 '22 10:03 cppden