Symbol database: fixed linenr problem in virtual destructors check

This commit is contained in:
Robert Reif 2010-08-13 23:57:53 +02:00 committed by Daniel Marjamäki
parent e9a3d03372
commit db78c3acdf
2 changed files with 35 additions and 37 deletions

View File

@ -1583,45 +1583,43 @@ 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;
const SpaceInfo *spaceInfo = info->derivedFrom[j].spaceInfo;
// Name of base class..
const std::string baseName = spaceInfo->className;
// Find the destructor declaration for the base class.
const Func *base_destructor = spaceInfo->getDestructor();
const Token *base = 0;
if (base_destructor)
base = base_destructor->token->tokAt(-2);
// Check that there is a destructor..
if (!base_destructor)
if (info->derivedFrom[j].access == Public && info->derivedFrom[j].spaceInfo)
{
if (spaceInfo->derivedFrom.empty())
virtualDestructorError(spaceInfo->classDef, baseName, derivedClass->str());
const SpaceInfo *spaceInfo = info->derivedFrom[j].spaceInfo;
continue;
// Name of base class..
const std::string baseName = spaceInfo->className;
// Find the destructor declaration for the base class.
const Func *base_destructor = spaceInfo->getDestructor();
const Token *base = 0;
if (base_destructor)
base = base_destructor->token;
// Check that there is a destructor..
if (!base_destructor)
{
if (spaceInfo->derivedFrom.empty())
virtualDestructorError(spaceInfo->classDef, baseName, derivedClass->str());
}
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 (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.)
if (base_destructor->access == Public)
virtualDestructorError(base, baseName, derivedClass->str());
}
}
}
else if (base_destructor->isVirtual)
continue;
// 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;
// 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.)
if (base_destructor->access == Public)
virtualDestructorError(base, baseName, derivedClass->str());
}
}
}

View File

@ -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[])