Merge pull request #55 from richq/sameexpr

Improve for same expression on both sides of operator
This commit is contained in:
Daniel Marjamäki 2011-11-05 10:28:14 -07:00
commit 580fef6951
2 changed files with 6 additions and 1 deletions

View File

@ -2337,7 +2337,7 @@ void CheckOther::checkDuplicateExpression()
continue;
for (const Token *tok = scope->classStart; tok && tok != scope->classStart->link(); tok = tok->next()) {
if (Token::Match(tok, "(|&&|%oror% %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %var% )|&&|%oror%") &&
if (Token::Match(tok, "return|(|&&|%oror% %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %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()) {

View File

@ -3408,6 +3408,11 @@ private:
"[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());
check("void foo() {\n"
" return a && a;\n"
"}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str());
}
void duplicateExpression2() { // ticket #2730