Fixed #9702 (False positive: Opposite inner condition when modifying member variable used by inner condition)
This commit is contained in:
parent
583ee7b70e
commit
76f759fcc4
|
@ -594,12 +594,14 @@ void CheckCondition::multiCondition2()
|
|||
if (!Token::simpleMatch(scope.classDef->linkAt(1), ") {"))
|
||||
continue;
|
||||
|
||||
bool functionCall = false;
|
||||
bool nonConstFunctionCall = false;
|
||||
bool nonlocal = false; // nonlocal variable used in condition
|
||||
std::set<int> vars; // variables used in condition
|
||||
visitAstNodes(condTok,
|
||||
[&](const Token *cond) {
|
||||
if (Token::Match(cond, "%name% (")) {
|
||||
functionCall = true;
|
||||
nonConstFunctionCall = isNonConstFunctionCall(cond, mSettings->library);
|
||||
if (nonConstFunctionCall)
|
||||
return ChildrenToVisit::done;
|
||||
|
@ -755,7 +757,8 @@ void CheckCondition::multiCondition2()
|
|||
break;
|
||||
}
|
||||
if ((tok->varId() && vars.find(tok->varId()) != vars.end()) ||
|
||||
(!tok->varId() && nonlocal)) {
|
||||
(!tok->varId() && nonlocal) ||
|
||||
(functionCall && tok->variable() && !tok->variable()->isLocal())) {
|
||||
if (Token::Match(tok, "%name% %assign%|++|--"))
|
||||
break;
|
||||
if (Token::Match(tok->astParent(), "*|.|[")) {
|
||||
|
|
|
@ -1921,6 +1921,19 @@ private:
|
|||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #9702
|
||||
check("struct A {\n"
|
||||
" void DoTest() {\n"
|
||||
" if (!IsSet()) {\n"
|
||||
" m_value = true;\n"
|
||||
" if (IsSet());\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" bool IsSet() const { return m_value; }\n"
|
||||
" bool m_value = false;\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void oppositeInnerConditionPointers() {
|
||||
|
|
Loading…
Reference in New Issue