[statechart] - templated states do not compile (transit not defined)

Hello, the code below doesn't compile (gcc-3.4.6 on Linux). 'transit in scope not defined' Any glue? Regards, Oliver #include <iostream> #include <stdexcept> #include <boost/mpl/list.hpp> #include <boost/statechart/custom_reaction.hpp> #include <boost/statechart/exception_translator.hpp> #include <boost/statechart/simple_state.hpp> #include <boost/statechart/state_machine.hpp> #include <boost/statechart/transition.hpp> namespace mpl = boost::mpl; namespace sc = boost::statechart; struct EvX : sc::event< EvX > {}; struct EvY : sc::event< EvY > {}; template< typename S > struct X; template< typename S > struct sm : public sc::state_machine< sm< S >, X< S >, std::allocator< void >, sc::exception_translator<>
{ void unconsumed_event( const sc::event_base & ) { throw std::runtime_error( "unknown event!" ); } }; template< typename S > struct Z : public sc::simple_state< Z< S >, sm< S >
{}; template< typename S > struct Y; template< typename S > struct X : public sc::simple_state< X< S >, sm< S >
{ typedef mpl::list< sc::transition< EvY, Y< S > >, sc::custom_reaction< sc::exception_thrown > > reactions; sc::result react( sc::exception_thrown const&) { try { throw; } catch ( std::exception const& e) { return transit< Z< S > >(); } <<=== error catch ( ... ) { return forward_event(); } } }; template< typename S > struct Y : public sc::simple_state< Y< S >, sm< S >
{}; int main() { try { sm< int > fsm; fsm.initiate(); fsm.process_event( EvY() ); fsm.process_event( EvX() ); return 0; } catch ( std::runtime_error const& e) { std::cerr << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return -1; }

Oliver.Kowalke@infineon.com wrote:
Hello, the code below doesn't compile (gcc-3.4.6 on Linux). 'transit in scope not defined' Any glue? Regards, Oliver
{ return transit< Z< S > >(); } <<=== error
Try { return this->template transit< Z< S > >(); } Can anyone comment on whay this is necessary? Is it standard behavior or a gcc limitation? gcc 4 has the same issue. If it is standard behavior, then the statechart docs need to be updated to reflect that because right now they don't include the "this->template " part. -Dave

David Greene wrote:
Oliver.Kowalke@infineon.com wrote:
Hello, the code below doesn't compile (gcc-3.4.6 on Linux). 'transit in scope not defined' Any glue? Regards, Oliver
{ return transit< Z< S > >(); } <<=== error
Try { return this->template transit< Z< S > >(); }
Can anyone comment on whay this is necessary? Is it standard behavior or a gcc limitation?
It's standard behavior, dependent name lookup in templates. I faintly remember an article that explained the problem really nicely but can't find it right now. In a nutshell, when going through the template the compiler cannot know whether transit< Z< S > >() is a call to a member function of the base class or a call to a ctor of a class template. IIRC, this is because of possible template specializations of the base class.
gcc 4 has the same issue. If it is standard behavior, then the statechart docs need to be updated to reflect that because right now they don't include the "this->template " part.
You mean an example doesn't use that syntax? I'd be grateful for a pointer. Thanks & Regards, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
participants (3)
-
Andreas Huber
-
David Greene
-
Oliver.Kowalke@infineon.com