Fixed #5941 (ValueFlow: Wrong value in subfunction under ?)

This commit is contained in:
Daniel Marjamäki 2014-06-24 19:30:46 +02:00
parent 1b5d127373
commit 54aede9086
3 changed files with 11 additions and 3 deletions

View File

@ -1212,9 +1212,9 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
if (Token::Match(tok2, "%varid% !!=", varid2)) {
for (std::list<ValueFlow::Value>::const_iterator val = argvalues.begin(); val != argvalues.end(); ++val)
setTokenValue(const_cast<Token*>(tok2), *val);
} else if (tok2->str() == "{") {
} else if (tok2->str() == "{" || tok2->str() == "?") {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str());
bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str() + ", at '" + tok2->str() + "'");
break;
}
}

View File

@ -4418,7 +4418,7 @@ private:
"[test.cpp:20] -> [test.cpp:1]: (style, inconclusive) The function parameter 'A' hides a typedef with the same name.\n"
"[test.cpp:21] -> [test.cpp:1]: (style, inconclusive) The variable 'A' hides a typedef with the same name.\n"
"[test.cpp:24] -> [test.cpp:1]: (style, inconclusive) The typedef 'A' hides a typedef with the same name.\n"
"[test.cpp:24]: (debug) ValueFlow bailout: parameter a\n", errout.str());
"[test.cpp:24]: (debug) ValueFlow bailout: parameter a, at '{'\n", errout.str());
}
void simplifyTypedef36() {

View File

@ -892,6 +892,14 @@ private:
code = "void f1(int x) { a=(abc)x; }\n"
"void f2(int y) { f1(123); }\n";
ASSERT_EQUALS(true, testValueOfX(code, 1U, 123));
code = "void f1(int x) {\n"
" x ?\n"
" 1024 / x :\n"
" 0; }\n"
"void f2() { f1(0); }";
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
}
};