Fix issue 9878: false positive: multiCondition (#2787)

This commit is contained in:
Paul Fultz II 2020-09-09 08:39:36 -05:00 committed by GitHub
parent 6ad3478fb7
commit bfe53fce04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -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()
}) {

View File

@ -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() {

View File

@ -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() {