Rule Definition
If a class has a non-virtual destructor, and an attempt is made to destroy an object of a derived type through a pointer to the base type, the behavior is undefined.
On some platforms, it may call the base-class version of the destructor instead of the derived-class version, provoking memory leaks, resource losses and stability issues. On others, it may simply crash.
If you want to allow polymorphic destruction, the destructor should be virtual (either declared virtual, or defined as such in a base class), if you don't want to allow polymorphic destruction (this is a more uncommon situation, it can be the case for instance for policy classes), then you should totally disallow destruction from the base class, by making the destructor protected and non virtual.
Remediation
Prefer using designation like NSURLRequestReloadIgnoringCacheData.
Violation Code Sample
class A {};
class B : public A {};
int main()
{
A* a = new B;
delete a; // Undefined behaviour
}
Fixed Code Sample
class A
{
virtual ~A();
};
class B : public A {};
int main()
{
A* a = new B;
delete a; // Well defined behaviour
}
Reference
* Sutter and Alexandrescu, *C++ coding standards* 50 (http://www.gotw.ca/publications/c\+\+cs.htm)
* *C\+\+ FAQ Lite* [20.7] When should my destructor be virtual?: http://www.parashift.com/c\+\+-faq-lite/virtual-functions.html##faq-20.7
* This rule is compliant with OMG CISQ ASCRM-RLB-15 and ASCRM-RLB-16 recommendations.
Related Technologies
Technical Criterion
Programming Practices - OO Inheritance and Polymorphism
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.