diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index e4aef04d0..8a50cd5b4 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -649,7 +649,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const // Check variable usage for (const Token *tok = scope->classDef->next(); tok && tok != scope->classEnd; tok = tok->next()) { - if (tok->str() == "for" || tok->str() == "while") { + if (tok->str() == "for" || tok->str() == "while" || tok->str() == "do") { for (std::list::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) { if ((*i)->classDef == tok) { // Find associated scope checkFunctionVariableUsage_iterateScopes(*i, variables, true, usedVariables); // Scan child scope diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 80107b5fd..a77292e52 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -625,6 +625,18 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'd' is assigned a value that is never used.\n", errout.str()); + functionVariableUsage("void foo()\n" + "{\n" + " int i = 0,code=10,d=10;\n" + " for(i = 0; i < 10; i++) {\n" + " std::cout<