Fixed #8288 (valueFlowGlobalVar: compound assignments)

This commit is contained in:
Daniel Marjamäki 2018-03-18 19:53:33 +01:00
parent e932c44ae6
commit 7699f6432b
2 changed files with 8 additions and 1 deletions

View File

@ -989,7 +989,7 @@ static void valueFlowGlobalStaticVar(TokenList *tokenList, const Settings *setti
continue;
if (Token::Match(tok->astParent(), "++|--|&") && !tok->astParent()->astOperand2())
vars.erase(tok->variable());
else if (tok->astParent()->str() == "=") {
else if (tok->astParent()->isAssignmentOp()) {
if (tok == tok->astParent()->astOperand1())
vars.erase(tok->variable());
else if (tokenList->isCPP() && Token::Match(tok->astParent()->tokAt(-2), "& %name% ="))

View File

@ -2721,6 +2721,13 @@ private:
"}"
"void other() { foo(x); }\n";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 321));
code = "static int x = 1;\n" // compound assignment
"void f() {\n"
" a = x;\n"
"}"
"void other() { x += b; }\n";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 1));
}
void valueFlowInlineAssembly() {