Same expression: Don't write warnings for same expression on both sides of arithmetical operators
This commit is contained in:
parent
71e61fb1ed
commit
033cb19656
|
@ -3349,7 +3349,7 @@ void CheckOther::checkDuplicateExpression()
|
||||||
|
|
||||||
// Experimental implementation
|
// Experimental implementation
|
||||||
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "[+*=]")) {
|
if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "[+-*/%=]")) {
|
||||||
if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1()))
|
if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1()))
|
||||||
continue;
|
continue;
|
||||||
if (isSameExpression(tok->astOperand1(), tok->astOperand2(), constStandardFunctions))
|
if (isSameExpression(tok->astOperand1(), tok->astOperand2(), constStandardFunctions))
|
||||||
|
|
|
@ -4703,16 +4703,14 @@ private:
|
||||||
check("void fun() {\n"
|
check("void fun() {\n"
|
||||||
" return a && a ||\n"
|
" return a && a ||\n"
|
||||||
" b == b &&\n"
|
" b == b &&\n"
|
||||||
" c - c &&\n"
|
|
||||||
" d > d &&\n"
|
" d > d &&\n"
|
||||||
" e < e &&\n"
|
" e < e &&\n"
|
||||||
" f ;\n"
|
" f ;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n"
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n"
|
||||||
"[test.cpp:3] -> [test.cpp:3]: (style) Same expression on both sides of '=='.\n"
|
"[test.cpp:3] -> [test.cpp:3]: (style) Same expression on both sides of '=='.\n"
|
||||||
"[test.cpp:4] -> [test.cpp:4]: (style) Same expression on both sides of '-'.\n"
|
"[test.cpp:4] -> [test.cpp:4]: (style) Same expression on both sides of '>'.\n"
|
||||||
"[test.cpp:5] -> [test.cpp:5]: (style) Same expression on both sides of '>'.\n"
|
"[test.cpp:5] -> [test.cpp:5]: (style) Same expression on both sides of '<'.\n", errout.str());
|
||||||
"[test.cpp:6] -> [test.cpp:6]: (style) Same expression on both sides of '<'.\n", errout.str());
|
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" return a && a;\n"
|
" return a && a;\n"
|
||||||
|
@ -4790,6 +4788,15 @@ private:
|
||||||
"}");
|
"}");
|
||||||
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"
|
||||||
|
" if (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"
|
||||||
|
" if (a / 1000 / 1000) {}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void duplicateIf1() { // ticket 3689 ( avoid false positive )
|
void duplicateIf1() { // ticket 3689 ( avoid false positive )
|
||||||
|
|
Loading…
Reference in New Issue