Fixed #9420 (False positive - redundantInitialization)
This commit is contained in:
parent
7977bbf456
commit
235ef0a01e
|
@ -1681,6 +1681,15 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
|
||||||
return Result(Result::Type::BAILOUT);
|
return Result(Result::Type::BAILOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mWhat == What::Reassign &&
|
||||||
|
Token::simpleMatch(tok, ";") &&
|
||||||
|
Token::simpleMatch(tok->astParent(), ";") &&
|
||||||
|
Token::simpleMatch(tok->astParent()->astParent(), "(") &&
|
||||||
|
Token::simpleMatch(tok->astParent()->astParent()->previous(), "for (") &&
|
||||||
|
!isUnchanged(tok, tok->astParent()->astParent()->link(), exprVarIds, local))
|
||||||
|
// TODO: This is a quick bailout to avoid FP #9420, there are false negatives (TODO_ASSERT_EQUALS)
|
||||||
|
return Result(Result::Type::BAILOUT);
|
||||||
|
|
||||||
if (expr->isName() && Token::Match(tok, "%name% (") && tok->str().find("<") != std::string::npos && tok->str().find(expr->str()) != std::string::npos)
|
if (expr->isName() && Token::Match(tok, "%name% (") && tok->str().find("<") != std::string::npos && tok->str().find(expr->str()) != std::string::npos)
|
||||||
return Result(Result::Type::BAILOUT);
|
return Result(Result::Type::BAILOUT);
|
||||||
|
|
||||||
|
|
|
@ -6629,6 +6629,19 @@ private:
|
||||||
" } while (false);\n"
|
" } while (false);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo(int num) {\n" // #9420 FP
|
||||||
|
" int a = num;\n"
|
||||||
|
" for (int b = 0; b < num; a = b++)\n"
|
||||||
|
" dostuff(a);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo(int num) {\n" // #9420 FN
|
||||||
|
" int a = num;\n"
|
||||||
|
" for (int b = 0; b < num; a = b++);\n"
|
||||||
|
"}");
|
||||||
|
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void redundantVarAssignment_after_switch() {
|
void redundantVarAssignment_after_switch() {
|
||||||
|
|
Loading…
Reference in New Issue