diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 95870c049..42c64c125 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -265,7 +265,8 @@ void Variables::write(unsigned int varid, const Token* tok) if (usage) { usage->_write = true; - usage->_read = false; + if (!usage->_var->isStatic()) + usage->_read = false; usage->_lastAccess = tok; } } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index f9e9c887c..27599cebd 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2901,6 +2901,14 @@ private: " return x ? a : c;\n" "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used\n", errout.str()); + + functionVariableUsage("void foo()\n" + "{\n" + " static int i = 0;\n" + " if(i < foo())\n" + " i += 5;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void localvarextern() {