Fixed #8339 (false positive: unread variable despite delete is used on it)

This commit is contained in:
Daniel Marjamäki 2018-11-14 17:04:14 +01:00
parent f1ce40a918
commit 69f6100d83
2 changed files with 20 additions and 2 deletions

View File

@ -928,8 +928,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
}
const Variables::VariableUsage *const var = variables.find(varid);
if (var && !var->_allocateMemory) {
variables.readAll(varid, tok);
if (var) {
if (!var->_aliases.empty())
variables.use(varid, tok);
else if (!var->_allocateMemory)
variables.readAll(varid, tok);
}
}

View File

@ -171,6 +171,7 @@ private:
TEST_CASE(localvarTemplate); // #4955 - variable is used as template parameter
TEST_CASE(localvarFuncPtr); // #7194
TEST_CASE(localvarAddr); // #7477
TEST_CASE(localvarDelete);
TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization);
@ -4104,6 +4105,20 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarDelete() { // #8339
functionVariableUsage("void reassign(char*& data, int size)"
"{"
" char* buf = new char[size];"
""
" char* tmp = data;"
" data = buf;"
" buf = tmp;"
""
" delete [] buf;"
"}");
ASSERT_EQUALS("", errout.str());
}
void chainedAssignment() {
// #5466
functionVariableUsage("void NotUsed(double* pdD, int n) {\n"