Fixed #4318 (False positive: 'unreadVariable')
This commit is contained in:
parent
79cd601ae7
commit
a2febc49d6
|
@ -735,9 +735,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
variables.use(tok->tokAt(2)->varId(), tok);
|
variables.use(tok->tokAt(2)->varId(), tok);
|
||||||
}
|
}
|
||||||
// assignment
|
// assignment
|
||||||
else if (!Token::Match(tok->tokAt(-2), "[;{}.] %var% (") &&
|
else if (Token::Match(tok, "*| ++|--| %var% ++|--| =") ||
|
||||||
(Token::Match(tok, "*| ++|--| %var% ++|--| =") ||
|
Token::Match(tok, "*| ( const| %type% *| ) %var% =")) {
|
||||||
Token::Match(tok, "*| ( const| %type% *| ) %var% ="))) {
|
|
||||||
bool dereference = false;
|
bool dereference = false;
|
||||||
bool pre = false;
|
bool pre = false;
|
||||||
bool post = false;
|
bool post = false;
|
||||||
|
@ -762,7 +761,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
post = true;
|
post = true;
|
||||||
|
|
||||||
const unsigned int varid1 = tok->varId();
|
const unsigned int varid1 = tok->varId();
|
||||||
const Token *start = tok;
|
const Token * const start = tok;
|
||||||
|
|
||||||
tok = doAssignment(variables, tok, dereference, scope);
|
tok = doAssignment(variables, tok, dereference, scope);
|
||||||
|
|
||||||
|
@ -777,7 +776,9 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
variables.read(varid1, tok);
|
variables.read(varid1, tok);
|
||||||
} else {
|
} else {
|
||||||
Variables::VariableUsage *var = variables.find(varid1);
|
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.writeAliases(varid1, tok);
|
||||||
variables.read(varid1, tok);
|
variables.read(varid1, tok);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1494,6 +1494,12 @@ private:
|
||||||
" return a + b;\n"
|
" return a + b;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
void localvar37() { // ticket #3078
|
||||||
|
|
Loading…
Reference in New Issue