Fixed #4311 (False positive: warning (selfAssignment): Redundant assignment of 'm_bar' to itself.

This commit is contained in:
Daniel Marjamäki 2012-11-03 13:18:43 +01:00
parent 24e71c479c
commit 6c2563c467
4 changed files with 2 additions and 34 deletions

View File

@ -1033,7 +1033,7 @@ void CheckOther::checkSelfAssignment()
const char selfAssignmentPattern[] = "%var% = %var% ;|=|)";
const Token *tok = Token::findmatch(_tokenizer->tokens(), selfAssignmentPattern);
while (tok) {
if (Token::Match(tok->previous(), "[;{}.]") &&
if (Token::Match(tok->previous(), "[;{}]") &&
tok->varId() && tok->varId() == tok->tokAt(2)->varId() &&
isTypeWithoutSideEffects(_tokenizer, symbolDatabase->getVariableFromVarId(tok->varId()))) {
bool err = true;

View File

@ -2624,7 +2624,7 @@ static void setVarIdClassFunction(Token * const startToken,
unsigned int *_varId)
{
for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) {
if (tok2->varId() == 0) {
if (tok2->varId() == 0 && tok2->previous()->str() != ".") {
const std::map<std::string,unsigned int>::const_iterator it = varlist.find(tok2->str());
if (it != varlist.end()) {
tok2->varId(it->second);

View File

@ -2791,16 +2791,6 @@ private:
" i = i;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'i' to itself.\n", errout.str());
// #4291 - id for variables accessed through 'this'
check("class Foo {\n"
" int var;\n"
" void func();\n"
"};\n"
"void Foo::func() {\n"
" this->var = var;\n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (warning) Redundant assignment of 'var' to itself.\n", errout.str());
}
void trac1132() {

View File

@ -250,7 +250,6 @@ private:
TEST_CASE(varid_in_class6); // #3755
TEST_CASE(varid_in_class7); // set variable id for struct members
TEST_CASE(varid_in_class8); // unknown macro in class
TEST_CASE(varid_in_class9); // #4291 - id for variables accessed through 'this'
TEST_CASE(varid_initList);
TEST_CASE(varid_operator);
TEST_CASE(varid_throw);
@ -3891,27 +3890,6 @@ private:
tokenizeDebugListing(code));
}
void varid_in_class9() { // #4291 - id for variables accessed through 'this'
const char code[] = "class A {\n"
" int var;\n"
"public:\n"
" void setVar();\n"
"};\n"
"void A::setVar() {\n"
" this->var = var;\n"
"}";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A {\n"
"2: int var@1 ;\n"
"3: public:\n"
"4: void setVar ( ) ;\n"
"5: } ;\n"
"6: void A :: setVar ( ) {\n"
"7: this . var@1 = var@1 ;\n"
"8: }\n",
tokenizeDebugListing(code));
}
void varid_initList() {
const char code[] = "class A {\n"
" A() : x(0) {}\n"