clarify calculation: fixed false negative for 'int x = a - b ? 2 : 3'
This commit is contained in:
parent
0d3874693a
commit
4ac3c7fe3b
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue