Virtual destructors : Don't check base classes when inheritance is
non-public
This commit is contained in:
parent
5ea2844b85
commit
0b35581d44
|
@ -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);
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue