CheckUnusedVar: Fix FP when there is class initialization
This commit is contained in:
parent
2f26195b23
commit
3bd5a4d10e
|
@ -1060,7 +1060,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok->varId() && tok->next() && (tok->next()->str() == ")" || tok->next()->isExtendedOp())) {
|
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(), "[;{}:]")) {
|
else if (Token::Match(tok, "%var% ;") && Token::Match(tok->previous(), "[;{}:]")) {
|
||||||
|
|
|
@ -157,6 +157,7 @@ private:
|
||||||
TEST_CASE(localvarRangeBasedFor); // #7075
|
TEST_CASE(localvarRangeBasedFor); // #7075
|
||||||
TEST_CASE(localvarAssignInWhile);
|
TEST_CASE(localvarAssignInWhile);
|
||||||
|
|
||||||
|
TEST_CASE(localvarCppInitialization);
|
||||||
TEST_CASE(localvarCpp11Initialization);
|
TEST_CASE(localvarCpp11Initialization);
|
||||||
|
|
||||||
TEST_CASE(chainedAssignment); // #5466
|
TEST_CASE(chainedAssignment); // #5466
|
||||||
|
@ -3832,6 +3833,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvarCppInitialization() {
|
||||||
|
functionVariableUsage("void foo() {\n"
|
||||||
|
" int buf[6];\n"
|
||||||
|
" Data data(buf);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void localvarCpp11Initialization() {
|
void localvarCpp11Initialization() {
|
||||||
// #6160
|
// #6160
|
||||||
functionVariableUsage("void foo() {\n"
|
functionVariableUsage("void foo() {\n"
|
||||||
|
|
Loading…
Reference in New Issue