Fixed #5089 ('inconclusive' output printed although --inconclusive not specified)

This commit is contained in:
Daniel Marjamäki 2013-10-23 06:42:52 +02:00
parent d1b03d9c31
commit 364757e1e1
2 changed files with 17 additions and 8 deletions

View File

@ -660,8 +660,11 @@ void CheckOther::checkRedundantAssignment()
if (error) { if (error) {
if (scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok) && warning) if (scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok) && warning)
redundantAssignmentInSwitchError(it->second, tok, tok->str()); redundantAssignmentInSwitchError(it->second, tok, tok->str());
else if (performance) else if (performance) {
redundantAssignmentError(it->second, tok, tok->str(), nonLocal(it->second->variable())); // Inconclusive for non-local variables const bool nonlocal = nonLocal(it->second->variable());
if (_settings->inconclusive || !nonlocal) // see #5089 - report inconclusive only when requested
redundantAssignmentError(it->second, tok, tok->str(), nonlocal); // Inconclusive for non-local variables
}
} }
it->second = tok; it->second = tok;
} }

View File

@ -6096,12 +6096,18 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
check("int i;\n" {
"void f() {\n" // non-local variable => only show warning when inconclusive is used
" i = 1;\n" const char code[] = "int i;\n"
" i = 1;\n" "void f() {\n"
"}"); " i = 1;\n"
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance, inconclusive) Variable 'i' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); " i = 1;\n"
"}";
check(code, "test.cpp", false, false); // inconclusive = false
ASSERT_EQUALS("", errout.str());
check(code, "test.cpp", false, true); // inconclusive = true
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance, inconclusive) Variable 'i' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str());
}
check("void f() {\n" check("void f() {\n"
" int i;\n" " int i;\n"