errmsg: added error message about virtual destructors
This commit is contained in:
parent
6acb123f1d
commit
897c02e3ed
|
@ -734,18 +734,14 @@ void CheckClass::virtualDestructor()
|
|||
base = Token::findmatch(_tokenizer->tokens(), (std::string("class ") + baseName[0] + " :|{").c_str());
|
||||
if (base)
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << _tokenizer->fileLine(base) << ": Class " << baseName[0] << " which is inherited by class " << derivedClass->str() << " does not have a virtual destructor";
|
||||
_errorLogger->reportErr(errmsg.str());
|
||||
_errorLogger->reportErr(ErrorMessage::virtualDestructor(_tokenizer, base, baseName[0], derivedClass->str()));
|
||||
}
|
||||
}
|
||||
|
||||
// There is a destructor. Check that it's virtual..
|
||||
else if (base->str() != "virtual")
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << _tokenizer->fileLine(base) << ": Class " << baseName[0] << " which is inherited by class " << derivedClass->str() << " does not have a virtual destructor";
|
||||
_errorLogger->reportErr(errmsg.str());
|
||||
_errorLogger->reportErr(ErrorMessage::virtualDestructor(_tokenizer, base, baseName[0], derivedClass->str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,7 +276,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
checkClass.constructors();
|
||||
|
||||
// Check that all base classes have virtual destructors
|
||||
checkClass.virtualDestructor();
|
||||
if (ErrorMessage::virtualDestructor(_settings))
|
||||
checkClass.virtualDestructor();
|
||||
|
||||
if (_settings._showAll)
|
||||
{
|
||||
|
|
|
@ -84,6 +84,15 @@ public:
|
|||
return s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string virtualDestructor(const Tokenizer *tokenizer, const Token *Location, const std::string &Base, const std::string &Derived)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor";
|
||||
}
|
||||
static bool virtualDestructor(const Settings &s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Memory leak: " + varname + "";
|
||||
|
|
|
@ -60,6 +60,7 @@ int main()
|
|||
err.push_back(Message("memsetClass", 0, "Using '%1' on class", "memfunc"));
|
||||
err.push_back(Message("memsetStruct", 0, "Using '%1' on struct that contains a 'std::%2'", "memfunc", "classname"));
|
||||
err.push_back(Message("operatorEq", Message::STYLE, "'operator=' should return something"));
|
||||
err.push_back(Message("virtualDestructor", 0, "Class %1 which is inherited by class %2 does not have a virtual destructor", "Base", "Derived"));
|
||||
|
||||
// checkmemoryleak.cpp..
|
||||
err.push_back(Message("memleak", 0, "Memory leak: %1", "varname"));
|
||||
|
|
Loading…
Reference in New Issue