Fixed #7263 (False negative: redundant assignment using +=)

This commit is contained in:
Daniel Marjamäki 2018-12-27 17:27:51 +01:00
parent a788512d66
commit 6fef02498c
2 changed files with 18 additions and 4 deletions

View File

@ -1191,9 +1191,11 @@ struct FwdAnalysisAllPaths::Result FwdAnalysisAllPaths::checkRecursive(const Tok
if (reassign)
return Result(Result::Type::WRITE, parent->astParent());
return Result(Result::Type::READ);
} else if (Token::Match(parent->astParent(), "%assign%") && !parent->astParent()->astParent() && parent == parent->astParent()->astOperand1()) {
continue;
} else {
// TODO: this is a quick bailout
return Result(Result::Type::BAILOUT);
return Result(Result::Type::BAILOUT, parent->astParent());
}
}

View File

@ -809,7 +809,8 @@ private:
" d += code;\n"
" }\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'd' is assigned a value that is never used.\n", "", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'd' is assigned a value that is never used.\n"
"[test.cpp:7]: (style) Variable 'd' is assigned a value that is never used.\n", errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -868,7 +869,8 @@ private:
" d += code;\n"
" } while(code < 20);\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'd' is assigned a value that is never used.\n", "", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'd' is assigned a value that is never used.\n"
"[test.cpp:7]: (style) Variable 'd' is assigned a value that is never used.\n", errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -2179,6 +2181,15 @@ private:
" status = x;\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void f()\n"
"{\n"
" int sum = 0U;\n"
" for (i = 0U; i < 2U; i++)\n"
" sum += 123;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'sum' is assigned a value that is never used.\n"
"[test.cpp:5]: (style) Variable 'sum' is assigned a value that is never used.\n", errout.str());
}
void localvaralias1() {
@ -3442,7 +3453,8 @@ private:
" int b = 2;\n"
" a |= b;\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n"
"[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
functionVariableUsage("void foo() {\n"
" int a = 1;\n"