clarify calculation: fixed false negative for 'int x = a - b ? 2 : 3'

This commit is contained in:
Daniel Marjamäki 2011-04-04 21:33:16 +02:00
parent 0d3874693a
commit 4ac3c7fe3b
2 changed files with 6 additions and 1 deletions

View File

@ -106,7 +106,7 @@ void CheckOther::clarifyCalculation()
}
else if (cond->isName() || cond->isNumber())
{
if (Token::Match(cond->previous(),("return|+|-|,|(|"+op).c_str()))
if (Token::Match(cond->previous(),("return|=|+|-|,|(|"+op).c_str()))
clarifyCalculationError(cond, op);
}
}

View File

@ -2296,6 +2296,11 @@ private:
" std::cout << x << 1 ? 2 : 3;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for << and ?\n", errout.str());
check("void f() {\n"
" int ab = a - b ? 2 : 3;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for - and ?\n", errout.str());
}
// clarify conditions with = and comparison