diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 7be6cf3c7..8e7cb0971 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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::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) == "*")) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index f340d58e8..16c65aae5 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -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"