GNU GCC (g++): Why does it generate multiple dtors?

First, the purposes of these functions are described in the Itanium C++ ABI; see definitions under “base object destructor”, “complete object destructor”, and “deleting destructor”. The mapping to mangled names is given in 5.1.4.

Basically:

  • D2 is the “base object destructor”. It destroys the object itself, as well as data members and non-virtual base classes.
  • D1 is the “complete object destructor”. It additionally destroys virtual base classes.
  • D0 is the “deleting object destructor”. It does everything the complete object destructor does, plus it calls operator delete to actually free the memory.

If you have no virtual base classes, D2 and D1 are identical; GCC will, on sufficient optimization levels, actually alias the symbols to the same code for both.

Leave a Comment