== Why is this an issue?

When a class with no `virtual` destructor is used as a base class, surprises can occur if pointers to instances of this class are used. Specifically, if an instance of a derived class is ``delete``d through a pointer to the base type, the behavior is undefined and can lead to resource leaks, crashes or corrupted memory. 

If it is not expected for base class pointers to be deleted, then the destructor should be made `protected` to avoid such a misuse.


=== Noncompliant code example

[source,cpp]
----
class Base { // Noncompliant: no destructor is supplied, and the default version is not virtual
public:
  Base() {}
  virtual void doSomething() {}
};

class Derived : public Base {
}

void f() {
  Base *p = new Derived();
  delete p; // Undefined behavior
}
----


=== Compliant solution

[source,cpp]
----
class Base {
public:
  Base() {}
  virtual ~Base() = default;
  virtual void doSomething() {}
};
----


== Resources

* https://wiki.sei.cmu.edu/confluence/x/5Xs-BQ[CERT, OOP52-CPP.] - Do not delete a polymorphic object without a virtual destructor
* http://www.gotw.ca/publications/mill18.htm[Virtuality article]
* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#c35-a-base-class-destructor-should-be-either-public-and-virtual-or-protected-and-non-virtual[C.35: A base class destructor should be either public and virtual, or protected and non-virtual]
* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#c127-a-class-with-a-virtual-function-should-have-a-virtual-or-protected-destructor[C.127: A class with a virtual function should have a virtual or protected destructor]

