Fixed #4723 (False positive: Pure virtual call within conditional clause)
conditional clauses directly in constructor/destructor cannot prevent pure virtual function call otherwise this part of the code would never been called
This commit is contained in:
parent
32e1831716
commit
67915749b0
|
@ -1996,6 +1996,10 @@ const std::list<const Token *> & CheckClass::callsPureVirtualFunction(const Func
|
||||||
for (const Token *tok = function.arg->link();
|
for (const Token *tok = function.arg->link();
|
||||||
tok && tok != function.functionScope->classEnd;
|
tok && tok != function.functionScope->classEnd;
|
||||||
tok = tok->next()) {
|
tok = tok->next()) {
|
||||||
|
if (function.type != Function::eConstructor &&
|
||||||
|
function.type != Function::eCopyConstructor &&
|
||||||
|
function.type != Function::eMoveConstructor &&
|
||||||
|
function.type != Function::eDestructor) {
|
||||||
if ((Token::simpleMatch(tok,") {") &&
|
if ((Token::simpleMatch(tok,") {") &&
|
||||||
tok->link() &&
|
tok->link() &&
|
||||||
Token::Match(tok->link()->previous(),"if|switch")) ||
|
Token::Match(tok->link()->previous(),"if|switch")) ||
|
||||||
|
@ -2005,6 +2009,7 @@ const std::list<const Token *> & CheckClass::callsPureVirtualFunction(const Func
|
||||||
tok = tok->linkAt(1);
|
tok = tok->linkAt(1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const Function * callFunction=tok->function();
|
const Function * callFunction=tok->function();
|
||||||
if (!callFunction ||
|
if (!callFunction ||
|
||||||
function.nestedIn != callFunction->nestedIn ||
|
function.nestedIn != callFunction->nestedIn ||
|
||||||
|
|
|
@ -5679,6 +5679,26 @@ private:
|
||||||
"A::~A()\n"
|
"A::~A()\n"
|
||||||
"{nonpure();}\n");
|
"{nonpure();}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout.str());
|
||||||
|
|
||||||
|
checkPureVirtualFunctionCall("class A\n"
|
||||||
|
"{\n"
|
||||||
|
" virtual void pure()=0;\n"
|
||||||
|
" A(bool b);\n"
|
||||||
|
"};\n"
|
||||||
|
"A::A(bool b)\n"
|
||||||
|
"{if (b) pure();}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str());
|
||||||
|
|
||||||
|
checkPureVirtualFunctionCall("class A\n"
|
||||||
|
" {\n"
|
||||||
|
" virtual void pure()=0; \n"
|
||||||
|
" virtual ~A(); \n"
|
||||||
|
" int m; \n"
|
||||||
|
"};\n"
|
||||||
|
"A::~A()\n"
|
||||||
|
"{if (b) pure();}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pureVirtualFunctionCallOtherClass() {
|
void pureVirtualFunctionCallOtherClass() {
|
||||||
|
|
Loading…
Reference in New Issue