Fixed #1605 (false positive: uninitialized variable)
This commit is contained in:
parent
45573ad101
commit
61b5a21ac9
|
@ -660,7 +660,7 @@ void CheckOther::functionVariableUsage()
|
|||
else if (Token::Match(tok, "%var% ="))
|
||||
varUsage[tok->str()].write = true;
|
||||
|
||||
else if (Token::Match(tok, "%var% [ %any% ] ="))
|
||||
else if (Token::Match(tok, "%var% [") && Token::Match(tok->next()->link(), "] ="))
|
||||
varUsage[tok->str()].write = true;
|
||||
|
||||
else if (Token::Match(tok, "else %var% ="))
|
||||
|
|
|
@ -69,6 +69,7 @@ private:
|
|||
TEST_CASE(localvar6);
|
||||
TEST_CASE(localvar7);
|
||||
TEST_CASE(localvar8);
|
||||
TEST_CASE(localvar9); // ticket #1605
|
||||
TEST_CASE(localvarasm);
|
||||
|
||||
// Don't give false positives for variables in structs/unions
|
||||
|
@ -525,6 +526,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvar9()
|
||||
{
|
||||
// ticket #1605
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" int a[10];\n"
|
||||
" for (int i = 0; i < 10; )\n"
|
||||
" a[i++] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'a' is assigned a value that is never used\n", errout.str());
|
||||
}
|
||||
|
||||
void localvarasm()
|
||||
{
|
||||
functionVariableUsage("void foo(int &b)\n"
|
||||
|
|
Loading…
Reference in New Issue