Fixed #2286 (Variable 'ownKilled' is assigned a value that is never used)
This commit is contained in:
parent
1cd6f16ecf
commit
02892499d2
|
@ -1616,7 +1616,7 @@ void CheckOther::functionVariableUsage()
|
||||||
if (Token::Match(tok->next(), "++|--"))
|
if (Token::Match(tok->next(), "++|--"))
|
||||||
post = true;
|
post = true;
|
||||||
|
|
||||||
unsigned int varid1 = tok->varId();
|
const unsigned int varid1 = tok->varId();
|
||||||
const Token *start = tok;
|
const Token *start = tok;
|
||||||
|
|
||||||
tok = tok->tokAt(doAssignment(variables, tok, dereference, scope));
|
tok = tok->tokAt(doAssignment(variables, tok, dereference, scope));
|
||||||
|
@ -1649,13 +1649,20 @@ void CheckOther::functionVariableUsage()
|
||||||
}
|
}
|
||||||
|
|
||||||
Variables::VariableUsage *var2 = variables.find(tok->varId());
|
Variables::VariableUsage *var2 = variables.find(tok->varId());
|
||||||
if (var2 && var2->_type == Variables::reference)
|
if (var2)
|
||||||
{
|
{
|
||||||
variables.writeAliases(tok->varId());
|
if (var2->_type == Variables::reference)
|
||||||
variables.read(tok->varId());
|
{
|
||||||
|
variables.writeAliases(tok->varId());
|
||||||
|
variables.read(tok->varId());
|
||||||
|
}
|
||||||
|
else if (tok->varId() != varid1 && Token::Match(tok, "%var% ."))
|
||||||
|
variables.use(tok->varId());
|
||||||
|
else if (tok->varId() != varid1 &&
|
||||||
|
var2->_type == Variables::standard &&
|
||||||
|
tok->strAt(-1) != "&")
|
||||||
|
variables.use(tok->varId());
|
||||||
}
|
}
|
||||||
else if (tok->varId() != varid1 && Token::Match(tok, "%var% . %var%"))
|
|
||||||
variables.use(tok->varId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *equal = tok->next();
|
const Token *equal = tok->next();
|
||||||
|
|
|
@ -78,6 +78,7 @@ private:
|
||||||
TEST_CASE(localvar28); // ticket #2205
|
TEST_CASE(localvar28); // ticket #2205
|
||||||
TEST_CASE(localvar29); // ticket #2206 (array initialization)
|
TEST_CASE(localvar29); // ticket #2206 (array initialization)
|
||||||
TEST_CASE(localvar30);
|
TEST_CASE(localvar30);
|
||||||
|
TEST_CASE(localvar31); // ticket #2286
|
||||||
TEST_CASE(localvaralias1);
|
TEST_CASE(localvaralias1);
|
||||||
TEST_CASE(localvaralias2); // ticket #1637
|
TEST_CASE(localvaralias2); // ticket #1637
|
||||||
TEST_CASE(localvaralias3); // ticket #1639
|
TEST_CASE(localvaralias3); // ticket #1639
|
||||||
|
@ -1325,6 +1326,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvar31() // ticket #2286
|
||||||
|
{
|
||||||
|
functionVariableUsage("void f() {\n"
|
||||||
|
" int x = 0;\n"
|
||||||
|
" a.x = x - b;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void localvaralias1()
|
void localvaralias1()
|
||||||
{
|
{
|
||||||
functionVariableUsage("void foo()\n"
|
functionVariableUsage("void foo()\n"
|
||||||
|
|
Loading…
Reference in New Issue