value flow: Fixed FP in ?:

This commit is contained in:
Daniel Marjamäki 2014-01-07 19:46:13 +01:00
parent 740f72fdbd
commit 1fb0b1750c
2 changed files with 11 additions and 0 deletions

View File

@ -62,6 +62,11 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
} else { } else {
continue; continue;
} }
if (Token::Match(tok->astParent(), "[?:]")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok, "variable " + var->nameToken()->str() + " stopping on " + tok->astParent()->str());
continue;
}
} else if (Token::Match(tok->previous(), "if|while ( %var% %oror%|&&|)") || } else if (Token::Match(tok->previous(), "if|while ( %var% %oror%|&&|)") ||
Token::Match(tok, "%oror%|&& %var% %oror%|&&|)")) { Token::Match(tok, "%oror%|&& %var% %oror%|&&|)")) {
varid = tok->next()->varId(); varid = tok->next()->varId();

View File

@ -82,6 +82,12 @@ private:
"}"; "}";
ASSERT_EQUALS(true, testValueOfX(code, 2U, 123)); ASSERT_EQUALS(true, testValueOfX(code, 2U, 123));
// bailout: ?:
bailout("void f(int x) {\n"
" y = ((x<0) ? x : ((x==2)?3:4));\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: variable x stopping on :\n", errout.str());
// bailout: if/else/etc // bailout: if/else/etc
bailout("void f(int x) {\n" bailout("void f(int x) {\n"
" if (x != 123) { b = x; }\n" " if (x != 123) { b = x; }\n"