Fixed false positive #5466

This commit is contained in:
PKEuS 2014-08-31 19:46:30 +02:00
parent 8f4662de92
commit b8918906e6
2 changed files with 15 additions and 1 deletions

View File

@ -1056,8 +1056,10 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
else if (tok->isAssignmentOp()) {
for (const Token *tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
if (tok2->varId()) {
if (tok2->next()->isAssignmentOp())
if (tok2->strAt(1) == "=")
variables.write(tok2->varId(), tok);
else if (tok2->next()->isAssignmentOp())
variables.use(tok2->varId(), tok);
else
variables.read(tok2->varId(), tok);
}

View File

@ -156,6 +156,8 @@ private:
TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe
TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto
TEST_CASE(chainedAssignment); // #5466
TEST_CASE(crash1);
TEST_CASE(crash2);
TEST_CASE(usingNamespace); // #4585
@ -3773,6 +3775,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void chainedAssignment() {
// #5466
functionVariableUsage("void NotUsed(double* pdD, int n) {\n"
" double sum = 0.0;\n"
" for (int i = 0; i<n; ++i)\n"
" pdD[i] = (sum += pdD[i]);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void crash1() {
functionVariableUsage("SAL_WNODEPRECATED_DECLARATIONS_PUSH\n"
"void convertToTokenArray() {\n"