CheckUnusedVar: dont report false positives for extern variables
This commit is contained in:
parent
2e3a08a8c1
commit
cb7757f650
|
@ -597,7 +597,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
if (scope->type != Scope::eClass && scope->type != Scope::eUnion && scope->type != Scope::eStruct) {
|
||||
// Find declarations
|
||||
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {
|
||||
if (i->isThrow())
|
||||
if (i->isThrow() || i->isExtern())
|
||||
continue;
|
||||
Variables::VariableType type = Variables::none;
|
||||
if (i->isArray() && (i->nameToken()->previous()->str() == "*" || i->nameToken()->strAt(-2) == "*"))
|
||||
|
|
|
@ -102,6 +102,7 @@ private:
|
|||
TEST_CASE(localvaralias10); // ticket #2004
|
||||
TEST_CASE(localvarasm);
|
||||
TEST_CASE(localvarstatic);
|
||||
TEST_CASE(localvarextern);
|
||||
TEST_CASE(localvardynamic1);
|
||||
TEST_CASE(localvardynamic2); // ticket #2904
|
||||
TEST_CASE(localvardynamic3); // ticket #3467
|
||||
|
@ -2793,6 +2794,14 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used\n", errout.str());
|
||||
}
|
||||
|
||||
void localvarextern() {
|
||||
functionVariableUsage("void foo() {\n"
|
||||
" extern int i;\n"
|
||||
" i = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvardynamic1() {
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue