Skip to content

pool<...> not initialized with passed dependency #437

@WojciechMigda

Description

@WojciechMigda

Expected Behavior

When a dependency is passed to a constructed state machine it should always be stored in its pool<>.

Actual Behavior

Passed dependency will not be stored in the state machine's pool if there are no events with signatures which explicitly use the type of the dependency.

Steps to Reproduce the Problem

https://godbolt.org/z/WTcbe9 (gcc and clang)

#include <https://raw.githubusercontent.com/boost-experimental/sml/master/include/boost/sml.hpp>

namespace sml = boost::sml;

namespace
{

struct EV {};

struct Dep {};

auto action = [](auto && event, auto && sm, auto && deps, auto && subs)
{
    auto dep = sml::aux::get<Dep &>(deps); // this line will fail to compile
    (void)dep;
};

struct my_state
{
    auto operator()() const
    {
        using namespace sml;

        return make_transition_table(
            *"idle"_s + event<EV> / action = "active"_s

            // comment out this line to get
            // error: invalid 'static_cast' from type 'boost::ext::sml::v1_1_3::aux::pool<>' to type 'boost::ext::sml::v1_1_3::aux::pool_type<{anonymous}::Dep&>&'
            ,"active"_s + event<EV> / [](Dep &){}
        );
    }
};

}

int main()
{
    Dep dep;

    sml::sm<my_state> sm{dep};
    sm.process_event(EV{});
}

In this example:

  1. There is a state machine with Dep instance passed as a dependency.
  2. There are two actions, one accepts the 4-parameter event/sm/deps/subs signature, with automatic type deduction. The other accepts explicit Dep type.
  3. Defined transitions use both actions.

If the transition which uses explicit Dep dependency type is uncommented, then everything compiles fine, and retrieval of the dependency in the 4-parameter action works.
If one comments out the transition with the explicit type action, then the other action no longer compiles. The error states that the compiler cannot cast pool<>. This indicates, that the dependency that was passed to the constructed state machine was not picked up.

Specifications

  • Version: master
  • Platform: linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions