Fixed #7588 (Opposite conditions in nested 'if' blocks lead to a dead code block.)
This commit is contained in:
parent
2ccd5aec1a
commit
16c06e5714
|
@ -471,7 +471,11 @@ void CheckCondition::oppositeInnerCondition()
|
|||
}
|
||||
if (Token::Match(tok, "%type% (") && nonlocal) // function call -> bailout if there are nonlocal variables
|
||||
break;
|
||||
else if ((tok->varId() && vars.find(tok->varId()) != vars.end()) ||
|
||||
// bailout if loop is seen.
|
||||
// TODO: handle loops.
|
||||
if (Token::Match(tok, "for|while|do"))
|
||||
break;
|
||||
if ((tok->varId() && vars.find(tok->varId()) != vars.end()) ||
|
||||
(!tok->varId() && nonlocal)) {
|
||||
if (Token::Match(tok, "%name% %assign%|++|--"))
|
||||
break;
|
||||
|
|
|
@ -1505,6 +1505,16 @@ private:
|
|||
" }\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||
|
||||
check("void foo(unsigned u) {\n"
|
||||
" if (u != 0) {\n"
|
||||
" for (int i=0; i<32; i++) {\n"
|
||||
" if (u == 0) {}\n" // <- don't warn
|
||||
" u = x;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// clarify conditions with = and comparison
|
||||
|
|
Loading…
Reference in New Issue