Fix issue 8738: Dont warn about multiconditions when value is known (#1369)
This commit is contained in:
parent
f7e7e9bd3c
commit
5a2362b2a0
|
@ -427,7 +427,11 @@ void CheckCondition::multiCondition()
|
|||
break;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2542,6 +2542,15 @@ private:
|
|||
" }\n"
|
||||
"}\n");
|
||||
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() {
|
||||
|
|
|
@ -4623,6 +4623,14 @@ private:
|
|||
"}\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());
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue