Fix issue 8738: Dont warn about multiconditions when value is known (#1369)

This commit is contained in:
Paul Fultz II 2018-09-07 08:02:34 -05:00 committed by Daniel Marjamäki
parent f7e7e9bd3c
commit 5a2362b2a0
3 changed files with 22 additions and 1 deletions

View File

@ -427,7 +427,11 @@ void CheckCondition::multiCondition()
break; break;
tok2 = tok2->tokAt(4); tok2 = tok2->tokAt(4);
if (isOverlappingCond(cond1, tok2->astOperand2(), true)) if (cond1 &&
tok2->astOperand2() &&
!cond1->hasKnownValue() &&
!tok2->astOperand2()->hasKnownValue() &&
isOverlappingCond(cond1, tok2->astOperand2(), true))
multiConditionError(tok2, cond1->linenr()); multiConditionError(tok2, cond1->linenr());
} }
} }

View File

@ -2542,6 +2542,15 @@ private:
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int activate = 0;\n"
" int foo = 0;\n"
" if (activate) {}\n"
" else if (foo) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'activate' is always false\n"
"[test.cpp:5]: (style) Condition 'foo' is always false\n", errout.str());
} }
void checkInvalidTestForOverflow() { void checkInvalidTestForOverflow() {

View File

@ -4623,6 +4623,14 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n" ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n"
"[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val < 0' is always false.\n", errout.str()); "[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val < 0' is always false.\n", errout.str());
check("void f() {\n"
" int activate = 0;\n"
" int foo = 0;\n"
" if (activate) {}\n"
" else if (foo) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void checkSignOfUnsignedVariable() { void checkSignOfUnsignedVariable() {