diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index ed0e8619c..68850f216 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 0494f4e63..aa919a5aa 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -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