Fixed #2004 (False positive in 'variable assigned a value but is never used' check)
This commit is contained in:
parent
1d78b5072d
commit
8ff1e71b22
|
@ -1634,7 +1634,6 @@ void CheckOther::functionVariableUsage()
|
|||
else
|
||||
{
|
||||
Variables::VariableUsage *var = variables.find(varid1);
|
||||
|
||||
if (var && var->_type == Variables::reference)
|
||||
{
|
||||
variables.writeAliases(varid1);
|
||||
|
@ -1642,6 +1641,13 @@ void CheckOther::functionVariableUsage()
|
|||
}
|
||||
else
|
||||
variables.write(varid1);
|
||||
|
||||
Variables::VariableUsage *var2 = variables.find(tok->varId());
|
||||
if (var2 && var2->_type == Variables::reference)
|
||||
{
|
||||
variables.writeAliases(tok->varId());
|
||||
variables.read(tok->varId());
|
||||
}
|
||||
}
|
||||
|
||||
const Token *equal = tok->next();
|
||||
|
|
|
@ -81,6 +81,7 @@ private:
|
|||
TEST_CASE(localvaralias7); // ticket #1732
|
||||
TEST_CASE(localvaralias8);
|
||||
TEST_CASE(localvaralias9); // ticket #1996
|
||||
TEST_CASE(localvaralias10); // ticket #2004
|
||||
TEST_CASE(localvarasm);
|
||||
TEST_CASE(localvarstatic);
|
||||
|
||||
|
@ -2146,6 +2147,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvaralias10() // ticket 2004
|
||||
{
|
||||
functionVariableUsage("void foo(Foo &foo)\n"
|
||||
"{\n"
|
||||
" Foo &ref = foo;\n"
|
||||
" int *x = &ref.x();\n"
|
||||
" *x = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarasm()
|
||||
{
|
||||
functionVariableUsage("void foo(int &b)\n"
|
||||
|
|
Loading…
Reference in New Issue