Fixed #5089 ('inconclusive' output printed although --inconclusive not specified)
This commit is contained in:
parent
d1b03d9c31
commit
364757e1e1
|
@ -660,8 +660,11 @@ void CheckOther::checkRedundantAssignment()
|
|||
if (error) {
|
||||
if (scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok) && warning)
|
||||
redundantAssignmentInSwitchError(it->second, tok, tok->str());
|
||||
else if (performance)
|
||||
redundantAssignmentError(it->second, tok, tok->str(), nonLocal(it->second->variable())); // Inconclusive for non-local variables
|
||||
else if (performance) {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
||||
check("int i;\n"
|
||||
"void f() {\n"
|
||||
" i = 1;\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());
|
||||
{
|
||||
// non-local variable => only show warning when inconclusive is used
|
||||
const char code[] = "int i;\n"
|
||||
"void f() {\n"
|
||||
" i = 1;\n"
|
||||
" 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"
|
||||
" int i;\n"
|
||||
|
|
Loading…
Reference in New Issue