Fixed #8198 (false positive: (warning) Same condition, second condition is always false)
This commit is contained in:
parent
ad494b996c
commit
abae5e0156
|
@ -497,7 +497,7 @@ void CheckCondition::multiCondition2()
|
||||||
if (!nonlocal && var) {
|
if (!nonlocal && var) {
|
||||||
if (!(var->isLocal() || var->isStatic() || var->isArgument()))
|
if (!(var->isLocal() || var->isStatic() || var->isArgument()))
|
||||||
nonlocal = true;
|
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
|
// TODO: if var is pointer check what it points at
|
||||||
nonlocal = true;
|
nonlocal = true;
|
||||||
}
|
}
|
||||||
|
@ -571,6 +571,8 @@ void CheckCondition::multiCondition2()
|
||||||
(!tok->varId() && nonlocal)) {
|
(!tok->varId() && nonlocal)) {
|
||||||
if (Token::Match(tok, "%name% %assign%|++|--"))
|
if (Token::Match(tok, "%name% %assign%|++|--"))
|
||||||
break;
|
break;
|
||||||
|
if (Token::Match(tok, "%name% <<|>>") && (!tok->valueType() || !tok->valueType()->isIntegral()))
|
||||||
|
break;
|
||||||
if (Token::Match(tok, "%name% [")) {
|
if (Token::Match(tok, "%name% [")) {
|
||||||
const Token *tok2 = tok->linkAt(1);
|
const Token *tok2 = tok->linkAt(1);
|
||||||
while (Token::simpleMatch(tok2, "] ["))
|
while (Token::simpleMatch(tok2, "] ["))
|
||||||
|
|
|
@ -1562,6 +1562,13 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str()); // just don't crash...
|
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() {
|
void oppositeInnerConditionUndeclaredVariable() {
|
||||||
|
|
Loading…
Reference in New Issue