Fixed false negative #5985: default argument values should not affect variable usage checking.
This commit is contained in:
parent
de66ed4071
commit
57c055fcc4
|
@ -724,7 +724,12 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
}
|
||||
|
||||
// Check variable usage
|
||||
for (const Token *tok = scope->classDef->next(); tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
const Token *tok;
|
||||
if (scope->type == Scope::eFunction)
|
||||
tok = scope->classStart->next();
|
||||
else
|
||||
tok = scope->classDef->next();
|
||||
for (; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->str() == "for" || tok->str() == "while" || tok->str() == "do") {
|
||||
for (std::list<Scope*>::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) {
|
||||
if ((*i)->classDef == tok) { // Find associated scope
|
||||
|
@ -736,7 +741,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
if (!tok)
|
||||
break;
|
||||
}
|
||||
if (tok->str() == "{") {
|
||||
if (tok->str() == "{" && tok != scope->classStart) {
|
||||
for (std::list<Scope*>::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) {
|
||||
if ((*i)->classStart == tok) { // Find associated scope
|
||||
checkFunctionVariableUsage_iterateScopes(*i, variables, false); // Scan child scope
|
||||
|
|
|
@ -862,6 +862,11 @@ private:
|
|||
" } while(code < 20);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("void foo(int j = 0) {\n" // #5985 - default function parameters should not affect checking results
|
||||
" int i = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str());
|
||||
}
|
||||
|
||||
void localvar2() {
|
||||
|
|
Loading…
Reference in New Issue