Suspicious condition: Better handling when rhs is non-numeric

This commit is contained in:
Daniel Marjamäki 2011-08-19 00:56:15 +02:00
parent f62d1d0122
commit e5ff920ea9
2 changed files with 6 additions and 1 deletions

View File

@ -152,7 +152,7 @@ void CheckOther::clarifyCondition()
tok2 = tok2->link(); tok2 = tok2->link();
else if (Token::Match(tok2, "&&|%oror%|?|)")) else if (Token::Match(tok2, "&&|%oror%|?|)"))
break; break;
else if (Token::Match(tok2, "<|<=|==|!=|>|>= %num% )")) else if (Token::Match(tok2, "<|<=|==|!=|>|>="))
{ {
clarifyConditionError(tok, tok->strAt(2) == "="); clarifyConditionError(tok, tok->strAt(2) == "=");
break; break;

View File

@ -2639,6 +2639,11 @@ private:
" if (x & 2 == 2) {}\n" " if (x & 2 == 2) {}\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n", errout.str());
check("void f() {\n"
" if (a & fred1.x == fred2.y) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n", errout.str());
} }
void incorrectStringCompare() void incorrectStringCompare()