Fixed #7405 (false positive: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.)

This commit is contained in:
Daniel Marjamäki 2017-09-05 22:03:29 +02:00
parent 4ca004c836
commit e5e6f37e41
2 changed files with 14 additions and 0 deletions

View File

@ -593,6 +593,13 @@ void CheckCondition::multiCondition2()
(!tok->varId() && nonlocal)) {
if (Token::Match(tok, "%name% %assign%|++|--"))
break;
if (Token::Match(tok->astParent(), "*|.|[")) {
const Token *parent = tok;
while (Token::Match(parent->astParent(), ".|[") || (Token::simpleMatch(parent->astParent(), "*") && !parent->astParent()->astOperand2()))
parent = parent->astParent();
if (Token::Match(parent->astParent(), "%assign%"))
break;
}
if (Token::Match(tok, "%name% <<|>>") && (!tok->valueType() || !tok->valueType()->isIntegral()))
break;
if (Token::Match(tok, "%name% [")) {

View File

@ -1522,6 +1522,13 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void test(float *f) {\n" // #7405
" if(*f>10) {\n"
" (*f) += 0.1f;\n"
" if(*f<10) {}\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void oppositeInnerConditionClass() {