tinyfsm icon indicating copy to clipboard operation
tinyfsm copied to clipboard

non virtual destructor

Open ghost opened this issue 6 years ago • 3 comments

Hi, I like you take on a simple state machine. When building with -Wnon-virtual-dtor you got some warning. I would add virtual ~MooreMachine() noexcept = default; to the MooreMachine template.

There is some reason I am missing why it is not there?

ghost avatar Jul 19 '19 09:07 ghost

Adding a virtual destructor would waste resources, and there is no reason to have one, as the MooreMachine class (and derived classes) is NOT intended to be deleted through a pointer to it.

Or am I missing something?

digint avatar Jul 19 '19 11:07 digint

If you have already a virtual method which resources are you wasting?

ghost avatar Jul 19 '19 11:07 ghost

If you have already a virtual method which resources are you wasting?

At least a vtable entry, not sure what else. Building examples/api/moore_machine.cpp results in:

without virtual destructor:

# size -B -d moore_machine
   text    data     bss     dec     hex filename
   3277     768     584    4629    1215 moore_machine

with virtual destructor virtual ~MooreMachine() noexcept = default;

# size -B -d moore_machine
   text    data     bss     dec     hex filename
   3662     808     600    5070    13ce moore_machine

digint avatar Jul 19 '19 11:07 digint