diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 9ef95295e..6068d65b4 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -497,7 +497,7 @@ void CheckCondition::multiCondition2() if (!nonlocal && var) { if (!(var->isLocal() || var->isStatic() || var->isArgument())) nonlocal = true; - else if ((var->isPointer() || var->isReference()) && !Token::simpleMatch(cond->astParent(), "!")) + else if ((var->isPointer() || var->isReference()) && !Token::Match(cond->astParent(), "%oror%|&&|!")) // TODO: if var is pointer check what it points at nonlocal = true; } @@ -571,6 +571,8 @@ void CheckCondition::multiCondition2() (!tok->varId() && nonlocal)) { if (Token::Match(tok, "%name% %assign%|++|--")) break; + if (Token::Match(tok, "%name% <<|>>") && (!tok->valueType() || !tok->valueType()->isIntegral())) + break; if (Token::Match(tok, "%name% [")) { const Token *tok2 = tok->linkAt(1); while (Token::simpleMatch(tok2, "] [")) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 097d15a83..557886130 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1562,6 +1562,13 @@ private: " }\n" "};"); ASSERT_EQUALS("", errout.str()); // just don't crash... + + check("bool f(std::ofstream &CFileStream) {\n" // #8198 + " if(!CFileStream.good()) { return; }\n" + " CFileStream << \"abc\";\n" + " if (!CFileStream.good()) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void oppositeInnerConditionUndeclaredVariable() {