Improve same expression check: take count of operations and assignments before the same expression and add missing 'return' pattern to the struct member variable part of the check.
This commit is contained in:
parent
d4a8184339
commit
99463d3368
|
@ -2341,7 +2341,7 @@ void CheckOther::checkDuplicateExpression()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (const Token *tok = scope->classStart; tok && tok != scope->classStart->link(); tok = tok->next()) {
|
for (const Token *tok = scope->classStart; tok && tok != scope->classStart->link(); tok = tok->next()) {
|
||||||
if (Token::Match(tok, "return|(|&&|%oror% %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %var% )|&&|%oror%|;") &&
|
if (Token::Match(tok, "=|%op%|return|(|&&|%oror% %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %var% )|&&|%oror%|;") &&
|
||||||
tok->strAt(1) == tok->strAt(3)) {
|
tok->strAt(1) == tok->strAt(3)) {
|
||||||
// float == float and float != float are valid NaN checks
|
// float == float and float != float are valid NaN checks
|
||||||
if (Token::Match(tok->tokAt(2), "==|!=") && tok->next()->varId()) {
|
if (Token::Match(tok->tokAt(2), "==|!=") && tok->next()->varId()) {
|
||||||
|
@ -2353,7 +2353,7 @@ void CheckOther::checkDuplicateExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
duplicateExpressionError(tok->next(), tok->tokAt(3), tok->strAt(2));
|
duplicateExpressionError(tok->next(), tok->tokAt(3), tok->strAt(2));
|
||||||
} else if (Token::Match(tok, "(|&&|%oror% %var% . %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %var% . %var% )|&&|%oror%") &&
|
} else if (Token::Match(tok, "=|%op%|return|(|&&|%oror% %var% . %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %var% . %var% )|&&|%oror%") &&
|
||||||
tok->strAt(1) == tok->strAt(5) && tok->strAt(3) == tok->strAt(7)) {
|
tok->strAt(1) == tok->strAt(5) && tok->strAt(3) == tok->strAt(7)) {
|
||||||
duplicateExpressionError(tok->next(), tok->tokAt(6), tok->strAt(4));
|
duplicateExpressionError(tok->next(), tok->tokAt(6), tok->strAt(4));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3413,6 +3413,16 @@ private:
|
||||||
" return a && a;\n"
|
" return a && a;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str());
|
||||||
|
|
||||||
|
check("void foo() {\n"
|
||||||
|
" a = b && b;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str());
|
||||||
|
|
||||||
|
check("void foo() {\n"
|
||||||
|
" a = a + b && b;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void duplicateExpression2() { // ticket #2730
|
void duplicateExpression2() { // ticket #2730
|
||||||
|
|
Loading…
Reference in New Issue