From cb7757f6507e56fe0febddb5f8cf4e4dea68598e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 28 Jun 2012 17:22:56 +0200 Subject: [PATCH] CheckUnusedVar: dont report false positives for extern variables --- lib/checkunusedvar.cpp | 2 +- test/testunusedvar.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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"