Fixed #8800 (Possible variable assignment ignored in boolean expression)

This commit is contained in:
Daniel Marjamäki 2018-11-26 13:59:28 +01:00
parent e18c846ed9
commit 2887ee10c0
2 changed files with 17 additions and 0 deletions

View File

@ -2363,6 +2363,14 @@ static bool valueFlowForward(Token * const startToken,
const Token *astTop = parent->astTop();
if (Token::simpleMatch(astTop->astOperand1(), "for ("))
tok2 = const_cast<Token*>(astTop->link());
// bailout if address of var is taken..
if (tok2->astParent() && tok2->astParent()->isUnaryOp("&")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "Taking address of " + tok2->str());
return false;
}
continue;
}

View File

@ -2239,6 +2239,15 @@ private:
" return x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 8U, 1));
code = "int f(int *);\n"
"int g() {\n"
" const int a = 1;\n"
" int x = 11;\n"
" c = (a && f(&x));\n"
" if (x == 42) {}\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 6U, 11));
}
void valueFlowForwardTernary() {