diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 2f42dcfba..80dde21d6 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -959,7 +959,7 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token if (!cond1 || !cond2) return false; - if (cond1->str() == "&&" && cond2->str() == "&&") { + if (!isNot && cond1->str() == "&&" && cond2->str() == "&&") { for (const Token* tok1: { cond1->astOperand1(), cond1->astOperand2() }) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 823947033..5b41aa0e9 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3658,6 +3658,15 @@ private: " if(b[1] == 2) {}\n" "}\n"); ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'b[1]==2' is always false\n", errout.str()); + + // #9878 + check("void f(bool a, bool b) {\n" + " if (a && b){;}\n" + " else if (!a && b){;}\n" + " else if (!a && !b){;}\n" + " else {;}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void duplicateCondition() { diff --git a/test/testother.cpp b/test/testother.cpp index 99f688320..22b5f7c76 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5310,7 +5310,7 @@ private: check("void f(int* x, bool b) {\n" " if ((!x && b) || (x != 0 && b)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Opposite expression on both sides of '||'.\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } void oppositeExpression() {