value flow: bailout for class variables that are non-const
This commit is contained in:
parent
ccda78f347
commit
84c5f47eb1
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue