Fixed false positive: Member variable not initialized in the constructor with array and (*this) (#5754)
This commit is contained in:
parent
cbb8360b30
commit
38af865560
|
@ -528,7 +528,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
|
|||
}
|
||||
|
||||
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(), "( * this ) . %var%"))
|
||||
continue;
|
||||
|
@ -700,6 +700,8 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
|
|||
// Assignment of array item of member variable?
|
||||
else if (Token::Match(ftok, "* %var% =")) {
|
||||
assignVar(ftok->next()->str(), scope, usage);
|
||||
} else if (Token::Match(ftok, "* this . %var% =")) {
|
||||
assignVar(ftok->strAt(3), scope, usage);
|
||||
}
|
||||
|
||||
// The functions 'clear' and 'Clear' are supposed to initialize variable.
|
||||
|
|
|
@ -2171,6 +2171,17 @@ private:
|
|||
" char name[255];\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5754
|
||||
check("class John\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" John() {*this->name = '\\0';}\n"
|
||||
"\n"
|
||||
"private:\n"
|
||||
" char name[255];\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray3() {
|
||||
|
|
Loading…
Reference in New Issue