Same expression: Don't write warnings for same expression on both sides of arithmetical operators

This commit is contained in:
Daniel Marjamäki 2013-11-17 17:21:39 +01:00
parent 71e61fb1ed
commit 033cb19656
2 changed files with 12 additions and 5 deletions

View File

@ -3349,7 +3349,7 @@ void CheckOther::checkDuplicateExpression()
// Experimental implementation
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()))
continue;
if (isSameExpression(tok->astOperand1(), tok->astOperand2(), constStandardFunctions))

View File

@ -4703,16 +4703,14 @@ private:
check("void fun() {\n"
" return a && a ||\n"
" b == b &&\n"
" c - c &&\n"
" d > d &&\n"
" e < e &&\n"
" f ;\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: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:6] -> [test.cpp:6]: (style) Same expression on both sides of '<'.\n", errout.str());
"[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", errout.str());
check("void foo() {\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());
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 )