diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 44215d422..d8b44ad31 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -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()); } } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 862c98539..65c42c93f 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -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() { diff --git a/test/testother.cpp b/test/testother.cpp index ac8de2f12..b0b27ab4d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {