Hi, I've noticed that the wrong logic is being used when performing the virtual destructor check.
void CheckClass::virtualDestructor()
{
// This error should only be given if:
// * base class doesn't have virtual destructor
// * derived class has non-empty destructor
// * base class is deleted
// unless inconclusive in which case:
// * base class has virtual members but doesn't have virtual destructor
in particular this condition:
* derived class has non-empty destructor
It doesn't consider member variables in the derived class.
Here's some example code that will be passed by cpp-check:
#include<iostream>#include<memory>usingnamespacestd;structA{A(){cout<<"A is constructing\n";}~A(){cout<<"A is destructing\n";}};structBase{};structDerived:Base{Aa;};intmain(){Base*p=newDerived();deletep;std::cout<<"Bye!\n";}
Output:
A is constructing
Bye!
These kind of missing virtual destructor errors are very important to detect correctly as they can cause silent memory corruption, resource leaks etc.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I've noticed that the wrong logic is being used when performing the virtual destructor check.
in particular this condition:
It doesn't consider member variables in the derived class.
Here's some example code that will be passed by cpp-check:
Output:
These kind of missing virtual destructor errors are very important to detect correctly as they can cause silent memory corruption, resource leaks etc.
I created ticket:
https://trac.cppcheck.net/ticket/9104
Feel free to implement a fix for this. It seems to me you have understood the cppcheck source code.