diff --git a/examples/api/Makefile b/examples/api/Makefile index 63b110e..6ed6b33 100644 --- a/examples/api/Makefile +++ b/examples/api/Makefile @@ -35,7 +35,7 @@ CXXFLAGS += -fno-rtti CXXFLAGS += -Wall -Wextra CXXFLAGS += -Wctor-dtor-privacy CXXFLAGS += -Wcast-align -Wpointer-arith -Wredundant-decls -CXXFLAGS += -Wshadow -Wcast-qual -Wcast-align -pedantic +CXXFLAGS += -Wshadow -Wcast-qual -Wcast-align -pedantic -Wnon-virtual-dtor # Produce debugging information (for use with gdb) #OPTIMIZER = -Og diff --git a/examples/api/moore_machine.cpp b/examples/api/moore_machine.cpp index 02a77da..0e16d53 100644 --- a/examples/api/moore_machine.cpp +++ b/examples/api/moore_machine.cpp @@ -14,6 +14,10 @@ struct Switch : tinyfsm::MooreMachine { /* pure virtual reaction (override required in all states) */ virtual void react(Toggle const &) = 0; + +// ~Switch() { +// std::cout << "* ~Switch()" << std::endl; +// } }; diff --git a/include/tinyfsm.hpp b/include/tinyfsm.hpp index 5a11f8a..700c262 100644 --- a/include/tinyfsm.hpp +++ b/include/tinyfsm.hpp @@ -224,6 +224,17 @@ namespace tinyfsm template struct MooreMachine : tinyfsm::Fsm { + // On the one hand giving an object a virtual destructor means it + // will have a vtable and therefore consume 4 (or 8 on 64 bit + // machines) additional bytes per-object for the vptr. + // + // For a class not intended to delete through a pointer to it, + // there is no reason whatsoever to have a virtual destructor. It + // would not only waste resources, but more importantly it would + // give users a wrong hint. + // + //virtual ~MooreMachine() noexcept = default; + virtual void entry(void) { }; /* entry actions in some states */ void exit(void) { }; /* no exit actions */ };