Clarify calculation: Fixed false positives when there are various function calls
This commit is contained in:
parent
ba5558748d
commit
df8504f0ea
|
@ -73,9 +73,9 @@ void CheckOther::clarifyCalculation()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->strAt(1) == "?") {
|
if (tok->str() == "?" && tok->previous()) {
|
||||||
// condition
|
// condition
|
||||||
const Token *cond = tok;
|
const Token *cond = tok->previous();
|
||||||
if (cond->isName() || cond->isNumber())
|
if (cond->isName() || cond->isNumber())
|
||||||
cond = cond->previous();
|
cond = cond->previous();
|
||||||
else if (cond->str() == ")")
|
else if (cond->str() == ")")
|
||||||
|
@ -97,8 +97,14 @@ void CheckOther::clarifyCalculation()
|
||||||
cond = cond->previous();
|
cond = cond->previous();
|
||||||
|
|
||||||
// skip previous multiplications..
|
// skip previous multiplications..
|
||||||
while (cond && cond->strAt(-1) == "*" && (cond->isName() || cond->isNumber()))
|
while (cond && cond->previous()) {
|
||||||
|
if ((cond->isName() || cond->isNumber()) && cond->previous()->str() == "*")
|
||||||
cond = cond->tokAt(-2);
|
cond = cond->tokAt(-2);
|
||||||
|
else if (cond->str() == ")")
|
||||||
|
cond = cond->link()->previous();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cond)
|
if (!cond)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -3338,6 +3338,11 @@ private:
|
||||||
" return x >> ! y ? 8 : 2;\n"
|
" return x >> ! y ? 8 : 2;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for >> and ?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for >> and ?\n", errout.str());
|
||||||
|
|
||||||
|
check("int f() {\n"
|
||||||
|
" return (shift < sizeof(int64_t)*8 ? 1 : 2);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// clarify conditions with = and comparison
|
// clarify conditions with = and comparison
|
||||||
|
|
Loading…
Reference in New Issue