Fixed #6147 (FP unreadVariable: variable assignment in function call argument list)

This commit is contained in:
Daniel Marjamäki 2016-08-02 08:50:04 +02:00
parent 31484133c0
commit 41526ef3a8
2 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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