Bei fehlendem virtual Destructor ein Warning? (Gnu g++)



  • Weiß jemand, ob man den Compiler dazu bringen kann eine Warnung auszugeben, wenn bei einer (puren) virtuellen Basisklasse der virtuelle Destructor fehlt?

    Gnu g++ und vielleicht MSC?


  • Mod

    Je nachdem, ob du Aufrufer oder Schreiber bist:

    -Wdelete-non-virtual-dtor: Warn when delete is used to destroy an instance of a class that has virtual functions and non-virtual destructor. It is unsafe to delete an instance of a derived class through a pointer to a base class if the base class does not have a virtual destructor. This warning is enabled by -Wall.

    -Wnon-virtual-dtor: Warn when a class has virtual functions and an accessible non-virtual destructor itself or in an accessible polymorphic base class, in which case it is possible but unsafe to delete an instance of a derived class through a pointer to the class itself or base class. This warning is automatically enabled if -Weffc++ is specified.


Log in to reply