Variable usage: only warn about variables that have variable id > 0
This commit is contained in:
parent
2bb07a55bd
commit
4ebf4caf66
|
@ -667,7 +667,8 @@ void Variables::addVar(const Token *name,
|
||||||
VariableType type,
|
VariableType type,
|
||||||
bool write_)
|
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)
|
void Variables::read(unsigned int varid)
|
||||||
|
|
|
@ -348,11 +348,14 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used\n", errout.str());
|
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"
|
functionVariableUsage("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int i(a);\n"
|
" int i(a);\n"
|
||||||
"}\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"
|
functionVariableUsage("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2036,11 +2039,14 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used\n", errout.str());
|
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"
|
functionVariableUsage("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" static int i(a);\n"
|
" static int i(a);\n"
|
||||||
"}\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"
|
functionVariableUsage("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue