Symbol database: fixed linenr problem in virtual destructors check
This commit is contained in:
parent
e9a3d03372
commit
db78c3acdf
|
@ -1583,9 +1583,8 @@ void CheckClass::virtualDestructor()
|
|||
for (unsigned int j = 0; j < info->derivedFrom.size(); ++j)
|
||||
{
|
||||
// Check if base class is public and exists in database
|
||||
if (info->derivedFrom[j].access != Public || !info->derivedFrom[j].spaceInfo)
|
||||
continue;
|
||||
|
||||
if (info->derivedFrom[j].access == Public && info->derivedFrom[j].spaceInfo)
|
||||
{
|
||||
const SpaceInfo *spaceInfo = info->derivedFrom[j].spaceInfo;
|
||||
|
||||
// Name of base class..
|
||||
|
@ -1595,28 +1594,24 @@ void CheckClass::virtualDestructor()
|
|||
const Func *base_destructor = spaceInfo->getDestructor();
|
||||
const Token *base = 0;
|
||||
if (base_destructor)
|
||||
base = base_destructor->token->tokAt(-2);
|
||||
base = base_destructor->token;
|
||||
|
||||
// Check that there is a destructor..
|
||||
if (!base_destructor)
|
||||
{
|
||||
if (spaceInfo->derivedFrom.empty())
|
||||
virtualDestructorError(spaceInfo->classDef, baseName, derivedClass->str());
|
||||
|
||||
continue;
|
||||
}
|
||||
else if (base_destructor->isVirtual)
|
||||
continue;
|
||||
|
||||
else if (!base_destructor->isVirtual)
|
||||
{
|
||||
// TODO: This is just a temporary fix, better solution is needed.
|
||||
// Skip situations where base class has base classes of its own, because
|
||||
// some of the base classes might have virtual destructor.
|
||||
// Proper solution is to check all of the base classes. If base class is not
|
||||
// found or if one of the base classes has virtual destructor, error should not
|
||||
// be printed. See TODO test case "virtualDestructorInherited"
|
||||
if (!Token::findmatch(_tokenizer->tokens(), (std::string("class ") + baseName + " {").c_str()))
|
||||
continue;
|
||||
|
||||
if (spaceInfo->derivedFrom.empty())
|
||||
{
|
||||
// Make sure that the destructor is public (protected or private
|
||||
// would not compile if inheritance is used in a way that would
|
||||
// cause the bug we are trying to find here.)
|
||||
|
@ -1624,6 +1619,9 @@ void CheckClass::virtualDestructor()
|
|||
virtualDestructorError(base, baseName, derivedClass->str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1418,7 +1418,7 @@ private:
|
|||
" public:\n"
|
||||
" ~B(){int a;}\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Class AA<double> which is inherited by class B does not have a virtual destructor\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:9]: (error) Class AA<double> which is inherited by class B does not have a virtual destructor\n", errout.str());
|
||||
}
|
||||
|
||||
void checkUninitVar(const char code[])
|
||||
|
|
Loading…
Reference in New Issue