Fix #11012 FP unassignedVariable when passed in init list (#5684)

This commit is contained in:
chrchr-github 2023-11-20 19:43:29 +01:00 committed by GitHub
parent d7c7a39afe
commit d09a6514cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -1090,7 +1090,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
}
else if (Token::Match(tok->previous(), "[{,] %var% [,}]")) {
variables.read(tok->varId(), tok);
variables.use(tok->varId(), tok);
}
else if (tok->varId() && Token::Match(tok, "%var% .")) {

View File

@ -176,6 +176,7 @@ private:
TEST_CASE(localvararray3); // ticket #3980
TEST_CASE(localvararray4); // ticket #4839
TEST_CASE(localvararray5); // ticket #7092
TEST_CASE(localvararray6);
TEST_CASE(localvarstring1);
TEST_CASE(localvarstring2); // ticket #2929
TEST_CASE(localvarconst1);
@ -6059,6 +6060,17 @@ private:
ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: v\n", errout.str());
}
void localvararray6() {
functionVariableUsage("struct S { int* p; };\n" // #11012
"void g(struct S* ps);\n"
"void f() {\n"
" int i[2];\n"
" struct S s = { i };\n"
" g(&s);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvarstring1() { // ticket #1597
functionVariableUsage("void foo() {\n"
" std::string s;\n"