fix #3043 (False Positive - Member variable 'ProgramRecPriorityInfo::profile' is not assigned a value in 'ProgramRecPriorityInfo::operator=')

This commit is contained in:
Robert Reif 2011-08-25 23:27:10 -04:00
parent 423a1ff64e
commit 1d7ab77251
2 changed files with 37 additions and 0 deletions

View File

@ -340,6 +340,10 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
// Goto the first token in this statement..
ftok = ftok->next();
// skip "return"
if (ftok->str() == "return")
ftok = ftok->next();
// Skip "( * this )"
if (Token::simpleMatch(ftok, "( * this ) ."))
{

View File

@ -66,6 +66,7 @@ private:
TEST_CASE(uninitVar19); // ticket #2792
TEST_CASE(uninitVar20); // ticket #2867
TEST_CASE(uninitVar21); // ticket #2947
TEST_CASE(uninitVar22); // ticket #3043
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -2263,6 +2264,38 @@ private:
ASSERT_EQUALS("", errout.str());
}
void uninitVar22() // ticket #3043
{
checkUninitVar("class Fred {\n"
" public:\n"
" Fred & operator=(const Fred &);\n"
" virtual Fred & clone(const Fred & other);\n"
" int x;\n"
"};\n"
"Fred & Fred::operator=(const Fred & other) {\n"
" return clone(other);\n"
"}\n"
"Fred & Fred::clone(const Fred & other) {\n"
" x = 0;\n"
" return *this;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("class Fred {\n"
" public:\n"
" Fred & operator=(const Fred &);\n"
" virtual Fred & clone(const Fred & other);\n"
" int x;\n"
"};\n"
"Fred & Fred::operator=(const Fred & other) {\n"
" return clone(other);\n"
"}\n"
"Fred & Fred::clone(const Fred & other) {\n"
" return *this;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='\n", errout.str());
}
void uninitVarArray1()
{
checkUninitVar("class John\n"