Template specialization fails in gcc < 7.0.0
HaskiDuan opened this issue · 3 comments
HaskiDuan commented
Hi Axel,
I'm trying to compile the tinyfsm under ubuntu 16.04, my g++ version is 5.4.0. But when I run make under example, I get the following error:
In file included from motor.cpp:1:0:
../../include/tinyfsm.hpp:235:63: error: specialization of ‘template<class F> static void tinyfsm::Fsm<F>::set_initial_state()’ in different namespace [-fpermissive]
template<> void tinyfsm::Fsm< _FSM >::set_initial_state(void) { \
^
motor.cpp:62:1: note: in expansion of macro ‘FSM_INITIAL_STATE’
FSM_INITIAL_STATE(Motor, Stopped)
^
../../include/tinyfsm.hpp:96:17: error: from definition of ‘template<class F> static void tinyfsm::Fsm<F>::set_initial_state()’ [-fpermissive]
static void set_initial_state();
^
Makefile:90: recipe for target 'motor.o' failed
make: *** [motor.o] Error 1
Would you help me to fix it ?
Thank you,
Husky
digint commented
does this help?
replace macro in "include/tinyfsm.hpp":
#define FSM_INITIAL_STATE(_FSM, _STATE) \
namespace tinyfsm { \
template<> void Fsm< _FSM >::set_initial_state(void) { \
current_state_ptr = &_state_instance< _STATE >::value; \
} \
}
Edit: You are probably hitting a compiler bug here, see:
HaskiDuan commented
Yeah, it works fine now.
Thanks for your code and help!