boost-ext / sml

C++14 State Machine library
https://boost-ext.github.io/sml
Boost Software License 1.0
1.16k stars 178 forks source link

Processing events from sub-states #173

Closed akowalew closed 5 years ago

akowalew commented 6 years ago

Hi!

I've just slightly modified "Defer/Process" example from the docs, by adding sub-state and processing event from it to the outer one:

#include <boost/sml.hpp>
#include <queue>

namespace sml = boost::sml;

namespace {
struct e1 {};
struct e2 {};
struct e3 {};

struct sub {
  auto operator()() const noexcept {
    using namespace sml;
    return make_transition_table(
      * "idle"_s + event<e2> / process(e3{}) = X
    );
  }
};

struct example {
  auto operator()() const noexcept {
    using namespace sml;
    return make_transition_table(
      * "idle"_s + event<e1> = state<sub>
      , state<sub> + event<e3> = X
    );
  }
};
}

int main() {
  using namespace sml;
  sm<example, sml::process_queue<std::queue>> sm;
}

Using Clang 6.0.1 I'm getting following compile error:

In file included from .../main.cpp:1:
.../sml.hpp:520:10: error: no matching function for call to 'get_id'
    id = aux::get_id<int, T>((ids_t *)0);
         ^~~~~~~~~~~~~~~~~~~
.../sml.hpp:1929:24: note: in instantiation of function template specialization 'boost::sml::v1_1_0::back::queue_event<(anonymous
      namespace)::e2>::queue_event<(anonymous namespace)::e3>' requested here
      sm.process_.push(event);
                       ^
.../sml.hpp:1745:12: note: in instantiation of function template specialization
      'boost::sml::v1_1_0::front::actions::process::process_impl<(anonymous namespace)::e3>::operator()<(anonymous namespace)::e2,
      boost::sml::v1_1_0::back::sm_impl<boost::sml::v1_1_0::back::sm_policy<(anonymous namespace)::sub, boost::sml::v1_1_0::back::policies::process_queue<queue> > >,
      boost::sml::v1_1_0::aux::pool<>, boost::sml::v1_1_0::aux::pool<boost::sml::v1_1_0::back::sm_impl<boost::sml::v1_1_0::back::sm_policy<(anonymous namespace)::example,
      boost::sml::v1_1_0::back::policies::process_queue<queue> > >, boost::sml::v1_1_0::back::sm_impl<boost::sml::v1_1_0::back::sm_policy<(anonymous namespace)::sub,
      boost::sml::v1_1_0::back::policies::process_queue<queue> > > > >' requested here
    return object(event, sm, deps, subs);

... and so on ...

After switching to GCC 8.1 I'm getting similar trace:

...

.../sml.hpp:522:29: error: no matching function for call to 'get_id<int, {anonymous}::e3>(boost::sml::v1_1_0::back::queue_event<{anonymous}::e2>::ids_t*)'
.../sml.hpp:399:13: note: candidate: 'template<class R, class T, int N> constexpr R boost::sml::v1_1_0::aux::get_id(boost::sml::v1_1_0::aux::type_id_type<N, T>*)'
.../sml.hpp:399:13: note:   template argument deduction/substitution failed:
.../sml.hpp:522:29: note:   mismatched types '{anonymous}::e3' and '{anonymous}::e2'
.../sml.hpp:522:29: note:   'boost::sml::v1_1_0::back::queue_event<{anonymous}::e2>::ids_t' {aka 'boost::sml::v1_1_0::aux::type_id<{anonymous}::e2>'} is not derived from 'boost::sml::v1_1_0::aux::type_id_type<N, {anonymous}::e3>'
.../sml.hpp:510:15: warning: 'static void boost::sml::v1_1_0::back::queue_event<Ts>::move_impl(boost::sml::v1_1_0::aux::byte (&)[boost::sml::v1_1_0::back::queue_event<Ts>::size], boost::sml::v1_1_0::back::queue_event<Ts>&&) [with T = {anonymous}::e3; Ts = {{anonymous}::e2}]' used but never defined
.../sml.hpp:505:15: warning: 'static void boost::sml::v1_1_0::back::queue_event<Ts>::dtor_impl(boost::sml::v1_1_0::aux::byte*) [with T = {anonymous}::e3; Ts = {{anonymous}::e2}]' used but never defined

Is that bug or not? Shall I process events from sub-states?

erikzenkerLogmein commented 5 years ago

Since you are trying to leave a sub state machine somehow, the issue is also related to #185. I am currently trying to replace an msm implementation with a sml one. But fail because I am not able to leave a sub state machine through multiple pseudo exit states (http://redboltz.wikidot.com/exit-point-pseudo-state).

kris-jusiak commented 5 years ago

Fixed by https://github.com/boost-experimental/sml/pull/302