CheckUnusedVar: Fix FP when there is class initialization

This commit is contained in:
Daniel Marjamäki 2016-01-01 16:04:13 +01:00
parent 2f26195b23
commit 3bd5a4d10e
2 changed files with 14 additions and 1 deletions

View File

@ -1060,7 +1060,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
}
else if (tok->varId() && tok->next() && (tok->next()->str() == ")" || tok->next()->isExtendedOp())) {
variables.readAll(tok->varId(), tok);
if (Token::Match(tok->tokAt(-2), "%name% ( %var% [,)]") &&
!(tok->tokAt(-2)->variable() && tok->tokAt(-2)->variable()->isReference()))
variables.use(tok->varId(), tok);
else
variables.readAll(tok->varId(), tok);
}
else if (Token::Match(tok, "%var% ;") && Token::Match(tok->previous(), "[;{}:]")) {

View File

@ -157,6 +157,7 @@ private:
TEST_CASE(localvarRangeBasedFor); // #7075
TEST_CASE(localvarAssignInWhile);
TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization);
TEST_CASE(chainedAssignment); // #5466
@ -3832,6 +3833,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarCppInitialization() {
functionVariableUsage("void foo() {\n"
" int buf[6];\n"
" Data data(buf);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarCpp11Initialization() {
// #6160
functionVariableUsage("void foo() {\n"