diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d9c50d040..36faf837f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 2110bd3ca..bbc1129d0 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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() {