CheckUnusedVar: Fix FP when there is class initialization
This commit is contained in:
parent
2f26195b23
commit
3bd5a4d10e
|
@ -1060,6 +1060,10 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
}
|
||||
|
||||
else if (tok->varId() && tok->next() && (tok->next()->str() == ")" || tok->next()->isExtendedOp())) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue