Improved %or% and & checks
This commit is contained in:
parent
4cb97edbaf
commit
d5664dd6cf
|
@ -2444,11 +2444,13 @@ void CheckOther::checkDuplicateExpression()
|
|||
if (scope->type != Scope::eFunction)
|
||||
continue;
|
||||
|
||||
complexDuplicateExpressionCheck(scope->classStart, "%or%", "");
|
||||
complexDuplicateExpressionCheck(scope->classStart, "%oror%", "");
|
||||
complexDuplicateExpressionCheck(scope->classStart, "&&", "%oror%");
|
||||
complexDuplicateExpressionCheck(scope->classStart, "&", "%oror%|%or%");
|
||||
complexDuplicateExpressionCheck(scope->classStart, "&&", "%oror%|%or%");
|
||||
|
||||
for (const Token *tok = scope->classStart; tok && tok != scope->classStart->link(); tok = tok->next()) {
|
||||
if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% ==|!=|<=|>=|<|>|-|%or% %var% )|&&|%oror%|;") &&
|
||||
if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% ==|!=|<=|>=|<|>|- %var% )|&&|%oror%|;") &&
|
||||
tok->strAt(1) == tok->strAt(3)) {
|
||||
// float == float and float != float are valid NaN checks
|
||||
if (Token::Match(tok->tokAt(2), "==|!=") && tok->next()->varId()) {
|
||||
|
@ -2460,7 +2462,7 @@ void CheckOther::checkDuplicateExpression()
|
|||
}
|
||||
|
||||
duplicateExpressionError(tok->next(), tok->tokAt(3), tok->strAt(2));
|
||||
} else if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% . %var% ==|!=|<=|>=|<|>|-|%or% %var% . %var% )|&&|%oror%") &&
|
||||
} else if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% . %var% ==|!=|<=|>=|<|>|- %var% . %var% )|&&|%oror%") &&
|
||||
tok->strAt(1) == tok->strAt(5) && tok->strAt(3) == tok->strAt(7)) {
|
||||
duplicateExpressionError(tok->next(), tok->tokAt(6), tok->strAt(4));
|
||||
}
|
||||
|
|
|
@ -3456,6 +3456,20 @@ private:
|
|||
" if (a && b || b && c) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" if (a && b | b && c) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" if ((a + b) | (a + b)) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '|'.\n", errout.str());
|
||||
check("void foo() {\n"
|
||||
" if ((a | b) & (a | b)) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&'.\n", errout.str());
|
||||
}
|
||||
|
||||
void duplicateExpression2() { // ticket #2730
|
||||
|
|
Loading…
Reference in New Issue