Fix issue 9878: false positive: multiCondition (#2787)
This commit is contained in:
parent
6ad3478fb7
commit
bfe53fce04
|
@ -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()
|
||||
}) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue