Fixed #1996 (False positive for 'Variable foo is assigned a value that is never used')

This commit is contained in:
Daniel Marjamäki 2010-08-31 20:33:28 +02:00
parent 513826d8c2
commit 1d78b5072d
2 changed files with 14 additions and 2 deletions

View File

@ -1665,11 +1665,11 @@ void CheckOther::functionVariableUsage()
else if (Token::Match(tok, "%var% [") && Token::Match(tok->next()->link(), "] ="))
{
unsigned int varid = tok->varId();
Variables::VariableUsage *var = variables.find(varid);
const Variables::VariableUsage *var = variables.find(varid);
if (var)
{
if (var->_type == Variables::pointer)
if (var->_type == Variables::pointer || var->_type == Variables::reference)
{
variables.read(varid);
variables.writeAliases(varid);

View File

@ -80,6 +80,7 @@ private:
TEST_CASE(localvaralias6); // ticket #1729
TEST_CASE(localvaralias7); // ticket #1732
TEST_CASE(localvaralias8);
TEST_CASE(localvaralias9); // ticket #1996
TEST_CASE(localvarasm);
TEST_CASE(localvarstatic);
@ -2134,6 +2135,17 @@ private:
"[test.cpp:5]: (style) Unused variable: b3\n", errout.str());
}
void localvaralias9() // ticket 1996
{
functionVariableUsage("void foo()\n"
"{\n"
" Foo foo;\n"
" Foo &ref = foo;\n"
" ref[0] = 123;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarasm()
{
functionVariableUsage("void foo(int &b)\n"