Fixed #8271 (FP uninitMemberVar: Handle method call in middle of statement)

This commit is contained in:
Daniel Marjamäki 2017-11-11 21:28:24 +01:00
parent 31a1cebc5f
commit 526d8b76a6
2 changed files with 19 additions and 5 deletions

View File

@ -573,11 +573,6 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
assignVar(ftok->next()->varId(), scope, usage); assignVar(ftok->next()->varId(), scope, usage);
} }
// Before a new statement there is "[{};()=[]" or ::
// We can also have a new statement after any operators or comparisons
if (! Token::Match(ftok, "%op%|%comp%|{|}|;|(|)|=|[|::"))
continue;
// If assignment comes after an && or || this is really inconclusive because of short circuiting // If assignment comes after an && or || this is really inconclusive because of short circuiting
if (Token::Match(ftok, "%oror%|&&")) if (Token::Match(ftok, "%oror%|&&"))
continue; continue;

View File

@ -143,6 +143,7 @@ private:
TEST_CASE(uninitVar28); // ticket #6258 TEST_CASE(uninitVar28); // ticket #6258
TEST_CASE(uninitVar29); TEST_CASE(uninitVar29);
TEST_CASE(uninitVar30); // ticket #6417 TEST_CASE(uninitVar30); // ticket #6417
TEST_CASE(uninitVar31); // ticket #8271
TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream); TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef); TEST_CASE(uninitVarTypedef);
@ -2327,6 +2328,24 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void uninitVar31() { // ticket #8271
check("void bar();\n"
"class MyClass {\n"
"public:\n"
" MyClass();\n"
" void Restart();\n"
"protected:\n"
" int m_retCode;\n"
"};\n"
"MyClass::MyClass() {\n"
" bar(),Restart();\n"
"}\n"
"void MyClass::Restart() {\n"
" m_retCode = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray1() { void uninitVarArray1() {
check("class John\n" check("class John\n"
"{\n" "{\n"