Fixed #5084 (False positive: (style) Same expression on both sides of '&&')
This commit is contained in:
parent
6aa03efa2f
commit
5d7e0aebf4
|
@ -3063,6 +3063,9 @@ void CheckOther::complexDuplicateExpressionCheck(const std::list<const Function*
|
|||
start = tok1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (tok1->isExpandedMacro())
|
||||
break;
|
||||
}
|
||||
const Token *end = 0;
|
||||
level = 0;
|
||||
|
@ -3077,8 +3080,13 @@ void CheckOther::complexDuplicateExpressionCheck(const std::list<const Function*
|
|||
end = tok1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (tok1->isExpandedMacro())
|
||||
break;
|
||||
}
|
||||
checkExpressionRange(constFunctions, start, end, toCheck);
|
||||
|
||||
if (start && end)
|
||||
checkExpressionRange(constFunctions, start, end, toCheck);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5957,12 +5957,14 @@ void Tokenizer::simplifyIfNotNull()
|
|||
else if (Token::Match(tok, "%var% != 0")) {
|
||||
deleteFrom = tok;
|
||||
tok->isPointerCompare(true);
|
||||
tok->isExpandedMacro(tok->isExpandedMacro() || tok->tokAt(2)->isExpandedMacro());
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "%var% .|:: %var% != 0")) {
|
||||
tok = tok->tokAt(2);
|
||||
deleteFrom = tok;
|
||||
tok->isPointerCompare(true);
|
||||
tok->isExpandedMacro(tok->isExpandedMacro() || tok->tokAt(2)->isExpandedMacro());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@ private:
|
|||
TEST_CASE(incorrectLogicOperator1);
|
||||
TEST_CASE(incorrectLogicOperator2);
|
||||
TEST_CASE(incorrectLogicOperator3);
|
||||
TEST_CASE(incorrectLogicOperator4);
|
||||
TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);
|
||||
TEST_CASE(incorrectLogicOp_condSwapping);
|
||||
TEST_CASE(sameExpression);
|
||||
|
@ -3982,6 +3983,13 @@ private:
|
|||
"[test.cpp:5]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3.\n", errout.str());
|
||||
}
|
||||
|
||||
void incorrectLogicOperator4() {
|
||||
check("void f(int x) {\n"
|
||||
" if (x && x != $0) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void secondAlwaysTrueFalseWhenFirstTrueError() {
|
||||
check("void f(int x) {\n"
|
||||
" if (x > 5 && x != 1)\n"
|
||||
|
|
Loading…
Reference in New Issue