value flow: bailout for class variables that are non-const

This commit is contained in:
Daniel Marjamäki 2014-01-19 11:55:02 +01:00
parent ccda78f347
commit 84c5f47eb1
2 changed files with 11 additions and 1 deletions

View File

@ -250,7 +250,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
continue;
// bailout: global non-const variables
if (var->isGlobal() && !var->isConst()) {
if (!(var->isLocal() || var->isArgument()) && !var->isConst()) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok, "global variable " + var->nameToken()->str());
continue;

View File

@ -369,6 +369,16 @@ private:
" if (x == 123) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (debug) ValueFlow bailout: global variable x\n", errout.str());
// class variable
const char *code;
code = "class Fred { int x; void clear(); void f(); };\n"
"void Fred::f() {\n"
" int a = x;\n"
" clear();\n" // <- x might be assigned
" if (x == 234) {}\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code,3,234));
}
void valueFlowBeforeConditionSwitch() {