Virtual destructors : Don't check base classes when inheritance is

non-public
This commit is contained in:
Daniel Marjamäki 2008-12-07 10:13:51 +00:00
parent 5ea2844b85
commit 0b35581d44
2 changed files with 8 additions and 2 deletions

View File

@ -693,6 +693,8 @@ void CheckClass::virtualDestructor()
derived = derived->tokAt(3);
while ( TOKEN::Match(derived, "%var%") )
{
bool isPublic = TOKEN::Match(derived, "public");
// What kind of inheritance is it.. public|protected|private
if ( TOKEN::Match( derived, "public|protected|private" ) )
derived = derived->next;
@ -707,6 +709,10 @@ void CheckClass::virtualDestructor()
if ( TOKEN::Match(derived, ",") )
derived = derived->next;
// If not public inheritance, skip checking of this base class..
if ( ! isPublic )
continue;
// Find the destructor declaration for the base class.
const TOKEN *base = TOKEN::findmatch(_tokenizer->tokens(), "%any% ~ %var1% (", baseName);
while (TOKEN::Match(base, "::"))

View File

@ -81,7 +81,7 @@ private:
checkVirtualDestructor("class Base { };\n"
"class Derived : Base { };");
ASSERT_EQUALS( std::string("[test.cpp:1]: Base class Base doesn't have a virtual destructor\n"), errout.str() );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void virtualDestructor3()