diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 138c8a5bf..ffbe2cd2d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2069,6 +2069,9 @@ void CheckOther::functionVariableUsage() if (dereference) { + Variables::VariableUsage *var = variables.find(varid1); + if (var && var->_type == Variables::array) + variables.write(varid1); variables.writeAliases(varid1); variables.read(varid1); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 3ad693053..3ddb229a0 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -96,6 +96,7 @@ private: TEST_CASE(localvarasm); TEST_CASE(localvarstatic); TEST_CASE(localvardynamic); + TEST_CASE(localvararray1); // ticket #2780 // Don't give false positives for variables in structs/unions TEST_CASE(localvarStruct1); @@ -2643,7 +2644,15 @@ private: " delete[] ptr;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + } + void localvararray1() + { + functionVariableUsage("void foo() {\n" + " int p[5];\n" + " *p = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };