Fixed #8926 (false positive: (style) Condition 's.x<=y' is always true)

This commit is contained in:
Daniel Marjamäki 2019-01-02 18:05:55 +01:00
parent bc234e2712
commit 236c88151f
2 changed files with 15 additions and 0 deletions

View File

@ -1160,6 +1160,11 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
if (Token::simpleMatch(tok, "asm ("))
return Result(Result::Type::BAILOUT);
if (mWhat == What::ValueFlow && Token::Match(tok, "while|for (")) {
// TODO: only bailout if expr is reassigned in loop
return Result(Result::Type::BAILOUT);
}
if (!local && Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) {
// TODO: this is a quick bailout
return Result(Result::Type::BAILOUT);

View File

@ -2437,6 +2437,16 @@ private:
ASSERT_EQUALS(true, values.front().isIntValue());
ASSERT_EQUALS(1, values.front().intvalue);
code = "void f() {\n"
" S s;\n"
" s.x = 1;\n"
" int y = 10;\n"
" while (s.x < y)\n" // s.x does not have known value
" s.x++;\n"
"}";
values = tokenValues(code, "<");
ASSERT_EQUALS(true, values.empty());
code = "void f() {\n"
" Hints hints;\n"
" hints.x = 1;\n"