AssignIf: handle parantheses. ticket: #2909
This commit is contained in:
parent
dd6982a616
commit
afc825da68
|
@ -92,19 +92,27 @@ void CheckAssignIf::comparison()
|
||||||
if (tok->str() != "&")
|
if (tok->str() != "&")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Token::Match(tok, "& %num% ==|!= %num% &&|%oror%|)"))
|
if (Token::Match(tok, "& %num% )| ==|!= %num% &&|%oror%|)"))
|
||||||
{
|
{
|
||||||
const MathLib::bigint num1 = MathLib::toLongNumber(tok->strAt(1));
|
const MathLib::bigint num1 = MathLib::toLongNumber(tok->strAt(1));
|
||||||
if (num1 < 0)
|
if (num1 < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const MathLib::bigint num2 = MathLib::toLongNumber(tok->strAt(3));
|
const Token *compareToken = tok->tokAt(2);
|
||||||
|
if (compareToken->str() == ")")
|
||||||
|
{
|
||||||
|
if (!Token::Match(compareToken->link()->previous(), "(|%oror%|&&"))
|
||||||
|
continue;
|
||||||
|
compareToken = compareToken->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
const MathLib::bigint num2 = MathLib::toLongNumber(compareToken->strAt(1));
|
||||||
if (num2 < 0)
|
if (num2 < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((num1 & num2) != num2)
|
if ((num1 & num2) != num2)
|
||||||
{
|
{
|
||||||
const std::string op(tok->strAt(2));
|
const std::string op(compareToken->str());
|
||||||
comparisonError(tok, op=="==" ? false : true);
|
comparisonError(tok, op=="==" ? false : true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,12 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Comparison is always false\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Comparison is always false\n", errout.str());
|
||||||
|
|
||||||
|
check("void foo(int x)\n"
|
||||||
|
"{\n"
|
||||||
|
" if ((x & 4) == 3);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (style) Comparison is always false\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x & 4 != 3);\n"
|
" if (x & 4 != 3);\n"
|
||||||
|
|
Loading…
Reference in New Issue