diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index a2d237c22..5bb4c17d9 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -627,6 +627,17 @@ void CheckCondition::multiCondition2() if (nonConstFunctionCall) continue; + std::vector varsInCond; + visitAstNodes(condTok, + [&varsInCond](const Token *cond) { + if (cond->variable()) { + const Variable *var = cond->variable(); + if(std::find(varsInCond.begin(), varsInCond.end(), var) == varsInCond.end()) + varsInCond.push_back(var); + } + return ChildrenToVisit::op1_and_op2; + }); + // parse until second condition is reached.. enum MULTICONDITIONTYPE { INNER, AFTER }; const Token *tok; @@ -710,6 +721,9 @@ void CheckCondition::multiCondition2() } } } + if (Token::Match(tok, "%name% (") && isVariablesChanged(tok, tok->linkAt(1), true, varsInCond, mSettings, mTokenizer->isCPP())) { + break; + } if (Token::Match(tok, "%type% (") && nonlocal && isNonConstFunctionCall(tok, mSettings->library)) // non const function call -> bailout if there are nonlocal variables break; if (Token::Match(tok, "case|break|continue|return|throw") && tok->scope() == endToken->scope()) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 295233112..3d2a05077 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1895,6 +1895,15 @@ private: " }\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); + + // #8938 + check("void Delete(SS_CELLCOORD upperleft) {\n" + " if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\n" + " GetActiveCell(&(upperleft.Col), &(upperleft.Row));\n" + " if (upperleft.Row == -1) {}\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void oppositeInnerConditionPointers() {