diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 0c55b32a1..7a75e60b1 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1072,6 +1072,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const } else if (Token::Match(tok, "[(,] (") && Token::Match(tok->next()->link(), ") %var% [,)]")) { variables.use(tok->next()->link()->next()->varId(), tok); // use = read + write + } else if (Token::Match(tok, "[(,] *| %var% =")) { + tok = tok->next(); + if (tok->str() == "*") + tok = tok->next(); + variables.use(tok->varId(), tok); } // function diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index c6bd4dde7..a4aa7255e 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1779,6 +1779,25 @@ private: " x(a, b=2);\n" // <- if param2 is passed-by-reference then b might be used in x "}"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("int foo() {\n" // ticket #6147 + " int a = 0;\n" + " bar(a=a+2);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("int foo() {\n" // ticket #6147 + " int a = 0;\n" + " bar(a=2);\n" + "}"); + TODO_ASSERT_EQUALS("error", "", errout.str()); + + functionVariableUsage("void bar(int);\n" + "int foo() {\n" + " int a = 0;\n" + " bar(a=a+2);\n" + "}"); + TODO_ASSERT_EQUALS("error", "", errout.str()); } void localvar37() { // ticket #3078