Fixed #5549 (ValueFlow: Handle static variables better in valueFlowAfterAssign)

This commit is contained in:
Daniel Marjamäki 2014-03-23 17:57:27 +01:00
parent 568b9677d7
commit 30fa187b30
2 changed files with 13 additions and 0 deletions

View File

@ -490,6 +490,12 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
break;
}
if (var->isStatic()) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " bailout when conditional code that contains var is seen");
break;
}
// Remove conditional values
std::list<ValueFlow::Value>::iterator it;
for (it = values.begin(); it != values.end();) {

View File

@ -498,6 +498,13 @@ private:
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 2));
code = "void f() {\n"
" static int x = 0;\n"
" if (x==0) x = getX();\n"
" return x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
// function
code = "void f() {\n"
" char *x = 0;\n"