unused variable: reading the value of variable in a for loop.. "for(;a;)" see ticket #18
This commit is contained in:
parent
f562f588fb
commit
121c0ee58f
|
@ -927,6 +927,9 @@ void CheckOther::functionVariableUsage()
|
|||
|
||||
if (Token::Match(tok, "[(,] %var% [,)]"))
|
||||
varUsage[ tok->strAt(1)] |= USAGE_WRITE;
|
||||
|
||||
if (Token::Match(tok, "; %var% ;"))
|
||||
varUsage[ tok->strAt(1)] |= USAGE_READ;
|
||||
}
|
||||
|
||||
// Check usage of all variables in the current scope..
|
||||
|
|
|
@ -75,6 +75,7 @@ private:
|
|||
TEST_CASE(localvarIf); // Usage in if
|
||||
TEST_CASE(localvarIfElse); // return tmp1 ? tmp2 : tmp3;
|
||||
TEST_CASE(localvarOpAssign); // a |= b;
|
||||
TEST_CASE(localvarFor); // for ( ; var; )
|
||||
}
|
||||
|
||||
void structmember1()
|
||||
|
@ -335,6 +336,15 @@ private:
|
|||
ASSERT_EQUALS(std::string("[test.cpp:2]: Variable 'a' is assigned a value that is never used\n"), errout.str());
|
||||
}
|
||||
|
||||
void localvarFor()
|
||||
{
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" int a = 1;\n"
|
||||
" for (;a;);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue