Variable usage: only warn about variables that have variable id > 0

This commit is contained in:
Daniel Marjamäki 2010-07-07 08:50:34 +02:00
parent 2bb07a55bd
commit 4ebf4caf66
2 changed files with 10 additions and 3 deletions

View File

@ -667,7 +667,8 @@ void Variables::addVar(const Token *name,
VariableType type,
bool write_)
{
_varUsage.insert(std::make_pair(name->varId(), VariableUsage(name, type, false, write_, false)));
if (name->varId() > 0)
_varUsage.insert(std::make_pair(name->varId(), VariableUsage(name, type, false, write_, false)));
}
void Variables::read(unsigned int varid)

View File

@ -348,11 +348,14 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used\n", errout.str());
// if a is undefined then Cppcheck can't determine if "int i(a)" is a
// * variable declaration
// * function declaration
functionVariableUsage("void foo()\n"
"{\n"
" int i(a);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used\n", errout.str());
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -2036,11 +2039,14 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used\n", errout.str());
// If "a" is undefined then Cppcheck can't determine whether
// "static int i(a);" is a variable declaration or a function
// declaration.
functionVariableUsage("void foo()\n"
"{\n"
" static int i(a);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used\n", errout.str());
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void foo()\n"
"{\n"