value flow: fixed todo assertion for handling of conditions

This commit is contained in:
Daniel Marjamäki 2014-01-19 09:31:40 +01:00
parent cdaa7abf7e
commit ccda78f347
2 changed files with 8 additions and 4 deletions

View File

@ -95,8 +95,12 @@ static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value,
static const Token * skipValueInConditionalExpression(const Token * const valuetok)
{
// Walk up the ast
const Token *prev = valuetok;
for (const Token *tok = valuetok->astParent(); tok; tok = tok->astParent()) {
if (!Token::Match(tok, "%oror%|&&|?|:"))
const bool prevIsLhs = (prev == tok->astOperand1());
prev = tok;
if (prevIsLhs || !Token::Match(tok, "%oror%|&&|?|:"))
continue;
// Is variable protected in LHS..

View File

@ -350,9 +350,9 @@ private:
" if (x != NULL) { }\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 3U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
bailout("void f(int x) {\n"
" if (x != 123) { b = x; }\n"