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); derived = derived->tokAt(3);
while ( TOKEN::Match(derived, "%var%") ) while ( TOKEN::Match(derived, "%var%") )
{ {
bool isPublic = TOKEN::Match(derived, "public");
// What kind of inheritance is it.. public|protected|private // What kind of inheritance is it.. public|protected|private
if ( TOKEN::Match( derived, "public|protected|private" ) ) if ( TOKEN::Match( derived, "public|protected|private" ) )
derived = derived->next; derived = derived->next;
@ -705,7 +707,11 @@ void CheckClass::virtualDestructor()
// Update derived so it's ready for the next loop. // Update derived so it's ready for the next loop.
derived = derived->next; derived = derived->next;
if ( TOKEN::Match(derived, ",") ) if ( TOKEN::Match(derived, ",") )
derived = derived->next; derived = derived->next;
// If not public inheritance, skip checking of this base class..
if ( ! isPublic )
continue;
// Find the destructor declaration for the base class. // Find the destructor declaration for the base class.
const TOKEN *base = TOKEN::findmatch(_tokenizer->tokens(), "%any% ~ %var1% (", baseName); const TOKEN *base = TOKEN::findmatch(_tokenizer->tokens(), "%any% ~ %var1% (", baseName);

View File

@ -81,7 +81,7 @@ private:
checkVirtualDestructor("class Base { };\n" checkVirtualDestructor("class Base { };\n"
"class Derived : Base { };"); "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() void virtualDestructor3()