From 84c5f47eb1da4b06d44d400e567063f3a34cf417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 19 Jan 2014 11:55:02 +0100 Subject: [PATCH] value flow: bailout for class variables that are non-const --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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() {