diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 08f31cedb..26815be03 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -286,7 +286,7 @@ static bool isOverlappingCond(const Token * const cond1, const Token * const con const MathLib::bigint value1 = MathLib::toLongNumber(num1->str()); const MathLib::bigint value2 = MathLib::toLongNumber(num2->str()); - return (value2 > 0 && (value1 & value2) == value2); + return ((value1 & value2) > 0); } return false; } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 8c503ef5a..037ff6fbd 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -457,6 +457,12 @@ private: " else if (x == 0) {}\n" "}",false); ASSERT_EQUALS("", errout.str()); + + check("void f(int x) {\n" + " if (x & 15) {}\n" + " else if (x == 40) {}\n" + "}",false); + ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); } void invalidMissingSemicolon() {