Fixed #4318 (False positive: 'unreadVariable')

This commit is contained in:
Daniel Marjamäki 2012-11-15 08:36:43 +01:00
parent 79cd601ae7
commit a2febc49d6
2 changed files with 12 additions and 5 deletions

View File

@ -735,9 +735,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
variables.use(tok->tokAt(2)->varId(), tok);
}
// assignment
else if (!Token::Match(tok->tokAt(-2), "[;{}.] %var% (") &&
(Token::Match(tok, "*| ++|--| %var% ++|--| =") ||
Token::Match(tok, "*| ( const| %type% *| ) %var% ="))) {
else if (Token::Match(tok, "*| ++|--| %var% ++|--| =") ||
Token::Match(tok, "*| ( const| %type% *| ) %var% =")) {
bool dereference = false;
bool pre = false;
bool post = false;
@ -762,7 +761,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
post = true;
const unsigned int varid1 = tok->varId();
const Token *start = tok;
const Token * const start = tok;
tok = doAssignment(variables, tok, dereference, scope);
@ -777,7 +776,9 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
variables.read(varid1, tok);
} else {
Variables::VariableUsage *var = variables.find(varid1);
if (var && var->_type == Variables::reference) {
if (var && Token::simpleMatch(start->previous(), ",")) {
variables.use(varid1, tok);
} else if (var && var->_type == Variables::reference) {
variables.writeAliases(varid1, tok);
variables.read(varid1, tok);
}

View File

@ -1494,6 +1494,12 @@ private:
" return a + b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("int f() {\n" // ticket #4318
" int a,b;\n"
" x(a, b=2);\n" // <- if param2 is passed-by-reference then b might be used in x
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvar37() { // ticket #3078