diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a0e094737..908fa9699 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1301,8 +1301,13 @@ void CheckOther::functionVariableUsage() variables.write(varid1); } + const Token *equal = tok->next(); + + if (Token::Match(tok->next(), "[ %any% ]")) + equal = tok->tokAt(4); + // checked for chained assignments - if (tok != start && tok->next()->str() == "=") + if (tok != start && equal->str() == "=") { Variables::VariableUsage *var = variables.find(tok->varId()); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 0e12833bf..51bfd9b9a 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -68,6 +68,7 @@ private: TEST_CASE(localvar20); // ticket #1799 TEST_CASE(localvar21); // ticket #1807 TEST_CASE(localvar22); // ticket #1811 + TEST_CASE(localvar23); // ticket #1808 TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias3); // ticket #1639 @@ -1203,6 +1204,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvar23() // ticket #1808 + { + functionVariableUsage("int foo(int c)\n" + "{\n" + " int a;\n" + " int b[10];\n" + " a = b[c] = 0;\n" + " return a;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void localvaralias1() { functionVariableUsage("void foo()\n"