Fixed #1495 (False -s positive: Member variable not assigned a value in operator=)
This commit is contained in:
parent
2a1edff77f
commit
9fd89d3bdc
|
@ -283,6 +283,9 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
|||
break;
|
||||
}
|
||||
|
||||
if (Token::Match(ftok->next(), "%var% . %var% ("))
|
||||
ftok = ftok->tokAt(2);
|
||||
|
||||
if (!Token::Match(ftok->next(), "%var%") &&
|
||||
!Token::Match(ftok->next(), "this . %var%") &&
|
||||
!Token::Match(ftok->next(), "* %var% =") &&
|
||||
|
|
|
@ -50,6 +50,7 @@ private:
|
|||
TEST_CASE(uninitVar4);
|
||||
TEST_CASE(uninitVar5);
|
||||
TEST_CASE(uninitVar6);
|
||||
TEST_CASE(uninitVar7);
|
||||
TEST_CASE(uninitVarEnum);
|
||||
TEST_CASE(uninitVarStream);
|
||||
TEST_CASE(uninitVarTypedef);
|
||||
|
@ -1538,6 +1539,28 @@ private:
|
|||
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()
|
||||
{
|
||||
checkUninitVar("class John\n"
|
||||
|
|
Loading…
Reference in New Issue