ValueFlow: inner and outer function return values

This commit is contained in:
Daniel Marjamäki 2016-10-22 17:22:57 +02:00
parent 77cd6c194f
commit 8a0f3009ff
2 changed files with 10 additions and 1 deletions

View File

@ -2491,7 +2491,7 @@ static bool isKnown(const Token * tok)
static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogger, const Settings *settings)
{
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
for (Token *tok = tokenlist->back(); tok; tok = tok->previous()) {
if (tok->str() != "(" || !tok->astOperand1() || !tok->astOperand1()->function())
continue;

View File

@ -1783,6 +1783,15 @@ private:
"void f() { x = 1 * one(); }";
ASSERT_EQUALS(1, valueOfTok(code, "*").intvalue);
ASSERT_EQUALS(true, valueOfTok(code, "*").isKnown());
code = "int add(int x, int y) {\n"
" return x+y;\n"
"}\n"
"void f2() {\n"
" x = 1 * add(1,add(2,3));\n"
"}";
ASSERT_EQUALS(6, valueOfTok(code, "*").intvalue);
ASSERT_EQUALS(true, valueOfTok(code, "*").isKnown());
}
void valueFlowFunctionDefaultParameter() {