diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 5ced2fcfc..16aba7fb0 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -989,7 +989,7 @@ static void valueFlowGlobalStaticVar(TokenList *tokenList, const Settings *setti continue; if (Token::Match(tok->astParent(), "++|--|&") && !tok->astParent()->astOperand2()) vars.erase(tok->variable()); - else if (tok->astParent()->str() == "=") { + else if (tok->astParent()->isAssignmentOp()) { if (tok == tok->astParent()->astOperand1()) vars.erase(tok->variable()); else if (tokenList->isCPP() && Token::Match(tok->astParent()->tokAt(-2), "& %name% =")) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index adb861168..8a0805ea4 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2721,6 +2721,13 @@ private: "}" "void other() { foo(x); }\n"; ASSERT_EQUALS(false, testValueOfX(code, 3U, 321)); + + code = "static int x = 1;\n" // compound assignment + "void f() {\n" + " a = x;\n" + "}" + "void other() { x += b; }\n"; + ASSERT_EQUALS(false, testValueOfX(code, 3U, 1)); } void valueFlowInlineAssembly() {