Miscellaneous-NoVirtualDestructor

Class needs a virtual destructor if at least one member function is virtual

Required inputs: IR

Classes that are used polymorphically should have a virtual destructor.

If an object is deleted through a pointer to a base class and that base class does not have a virtual destructor, undefined behavior occurs.

Example
class C {
    C() {} // explicit constructor, may take arguments
    C(const C&) = delete;
    C& operator=(const C&) = delete;
    virtual ~C() { }
};
Note that the GeneralPurpose-RuleOfThree requires that you also declare copy constructor and copy assignment operators when declaring a virtual destructor. You should declare these as deleted if the class is not supposed to be copyable.

Possible Messages

Key

Text

Severity

Disabled

missing_virtual_destructor

Class needs a virtual destructor.

None

False

Options

accept_none_destructor

accept_none_destructor : bool = True

If set true, classes without any destructor are tolerated.