Fixed #1501 (false positive: Variable 'n' is assigned a value that is never used)
This commit is contained in:
parent
15d67a2369
commit
235404077f
|
@ -535,6 +535,10 @@ void CheckOther::functionVariableUsage()
|
|||
|
||||
else if (Token::Match(tok, "; %var% ;"))
|
||||
varUsage[ tok->strAt(1)].read = true;
|
||||
|
||||
else if (Token::Match(tok, "++|-- %var%") ||
|
||||
Token::Match(tok, "%var% ++|--"))
|
||||
varUsage[tok->strAt(1)].use();
|
||||
}
|
||||
|
||||
// Check usage of all variables in the current scope..
|
||||
|
|
|
@ -64,6 +64,7 @@ private:
|
|||
TEST_CASE(localvar3);
|
||||
TEST_CASE(localvar4);
|
||||
TEST_CASE(localvar5);
|
||||
TEST_CASE(localvar6);
|
||||
|
||||
// Don't give false positives for variables in structs/unions
|
||||
TEST_CASE(localvarStruct1);
|
||||
|
@ -273,6 +274,18 @@ private:
|
|||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
void localvar6()
|
||||
{
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" int a = 0;\n"
|
||||
" int b[10];\n"
|
||||
" for (int i=0;i<10;++i)\n"
|
||||
" b[i] = ++a;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void localvarStruct1()
|
||||
|
|
Loading…
Reference in New Issue