Fixed #1495 (False -s positive: Member variable not assigned a value in operator=)

This commit is contained in:
Daniel Marjamäki 2010-06-24 20:09:26 +02:00
parent 2a1edff77f
commit 9fd89d3bdc
2 changed files with 26 additions and 0 deletions

View File

@ -283,6 +283,9 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
break; break;
} }
if (Token::Match(ftok->next(), "%var% . %var% ("))
ftok = ftok->tokAt(2);
if (!Token::Match(ftok->next(), "%var%") && if (!Token::Match(ftok->next(), "%var%") &&
!Token::Match(ftok->next(), "this . %var%") && !Token::Match(ftok->next(), "this . %var%") &&
!Token::Match(ftok->next(), "* %var% =") && !Token::Match(ftok->next(), "* %var% =") &&

View File

@ -50,6 +50,7 @@ private:
TEST_CASE(uninitVar4); TEST_CASE(uninitVar4);
TEST_CASE(uninitVar5); TEST_CASE(uninitVar5);
TEST_CASE(uninitVar6); TEST_CASE(uninitVar6);
TEST_CASE(uninitVar7);
TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream); TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef); TEST_CASE(uninitVarTypedef);
@ -1538,6 +1539,28 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void uninitVar7()
{
checkUninitVar("class Foo {\n"
" int a;\n"
"public:\n"
" Foo() : a(0) {}\n"
" Foo& operator=(const Foo&);\n"
" void Swap(Foo& rhs);\n"
"};\n"
"\n"
"void Foo::Swap(Foo& rhs) {\n"
" std::swap(a,rhs.a);\n"
"}\n"
"\n"
"Foo& Foo::operator=(const Foo& rhs) {\n"
" Foo copy(rhs);\n"
" copy.Swap(*this);\n"
" return *this;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray1() void uninitVarArray1()
{ {
checkUninitVar("class John\n" checkUninitVar("class John\n"