ValueFlow: Fixed 'function call => calculation' value flow

This commit is contained in:
Daniel Marjamäki 2014-06-13 16:34:57 +02:00
parent 5c2ed8450e
commit ad879320e5
2 changed files with 11 additions and 2 deletions

View File

@ -1059,8 +1059,8 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
const unsigned int varid2 = arg->nameToken()->varId();
for (const Token *tok2 = functionScope->classStart->next(); tok2 != functionScope->classEnd; tok2 = tok2->next()) {
if (Token::Match(tok2, "%varid% !!=", varid2)) {
std::list<ValueFlow::Value> &values = const_cast<Token*>(tok2)->values;
values.insert(values.begin(), argvalues.begin(), argvalues.end());
for (std::list<ValueFlow::Value>::const_iterator val = argvalues.begin(); val != argvalues.end(); ++val)
setTokenValue(const_cast<Token*>(tok2), *val);
} else if (tok2->str() == "{") {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str());

View File

@ -158,6 +158,15 @@ private:
ASSERT_EQUALS(2U, values.size());
ASSERT_EQUALS(4, values.front().intvalue);
ASSERT_EQUALS(16, values.back().intvalue);
// function call => calculation
code = "void f(int x) {\n"
" a = x + 8;\n"
"}\n"
"void callf() {\n"
" f(7);\n"
"}";
ASSERT_EQUALS(15, valueOfTok(code, "+").intvalue);
}
void valueFlowBeforeCondition() {