Fixed ticket #578 (missing virtual destructor not detected)
http://sourceforge.net/apps/trac/cppcheck/ticket/578
This commit is contained in:
parent
0db35229cb
commit
93604dd344
|
@ -710,9 +710,20 @@ void CheckClass::virtualDestructor()
|
|||
baseName[1] = 0;
|
||||
|
||||
// Update derived so it's ready for the next loop.
|
||||
derived = derived->next();
|
||||
do
|
||||
{
|
||||
if (derived->str() == "{")
|
||||
break;
|
||||
|
||||
if (derived->str() == ",")
|
||||
{
|
||||
derived = derived->next();
|
||||
break;
|
||||
}
|
||||
|
||||
derived = derived->next();
|
||||
}
|
||||
while (derived);
|
||||
|
||||
// If not public inheritance, skip checking of this base class..
|
||||
if (! isPublic)
|
||||
|
|
|
@ -42,6 +42,7 @@ private:
|
|||
TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error
|
||||
TEST_CASE(virtualDestructorProtected);
|
||||
TEST_CASE(virtualDestructorInherited);
|
||||
TEST_CASE(virtualDestructorTemplate);
|
||||
|
||||
TEST_CASE(uninitVar1);
|
||||
TEST_CASE(uninitVarEnum);
|
||||
|
@ -307,6 +308,28 @@ private:
|
|||
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class A which is inherited by class B does not have a virtual destructor\n", errout.str());
|
||||
}
|
||||
|
||||
void virtualDestructorTemplate()
|
||||
{
|
||||
// Base class has protected destructor, it makes Base *p = new Derived(); fail
|
||||
// during compilation time, so error is not possible. => no error
|
||||
checkVirtualDestructor("template <typename T> class A\n"
|
||||
"{\n"
|
||||
" public:\n"
|
||||
" virtual ~A(){}\n"
|
||||
"};\n"
|
||||
"template <typename T> class AA\n"
|
||||
"{\n"
|
||||
" public:\n"
|
||||
" ~AA(){}\n"
|
||||
"};\n"
|
||||
"class B : public A<int>, public AA<double>\n"
|
||||
"{\n"
|
||||
" public:\n"
|
||||
" ~B(){int a;}\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Class AA which is inherited by class B does not have a virtual destructor\n", errout.str());
|
||||
}
|
||||
|
||||
void checkUninitVar(const char code[])
|
||||
{
|
||||
// Tokenize..
|
||||
|
|
Loading…
Reference in New Issue