Skip to content

Commit d09a651

Browse files
Fix #11012 FP unassignedVariable when passed in init list (#5684)
1 parent d7c7a39 commit d09a651

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/checkunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
10901090
}
10911091

10921092
else if (Token::Match(tok->previous(), "[{,] %var% [,}]")) {
1093-
variables.read(tok->varId(), tok);
1093+
variables.use(tok->varId(), tok);
10941094
}
10951095

10961096
else if (tok->varId() && Token::Match(tok, "%var% .")) {

test/testunusedvar.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class TestUnusedVar : public TestFixture {
176176
TEST_CASE(localvararray3); // ticket #3980
177177
TEST_CASE(localvararray4); // ticket #4839
178178
TEST_CASE(localvararray5); // ticket #7092
179+
TEST_CASE(localvararray6);
179180
TEST_CASE(localvarstring1);
180181
TEST_CASE(localvarstring2); // ticket #2929
181182
TEST_CASE(localvarconst1);
@@ -6059,6 +6060,17 @@ class TestUnusedVar : public TestFixture {
60596060
ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: v\n", errout.str());
60606061
}
60616062

6063+
void localvararray6() {
6064+
functionVariableUsage("struct S { int* p; };\n" // #11012
6065+
"void g(struct S* ps);\n"
6066+
"void f() {\n"
6067+
" int i[2];\n"
6068+
" struct S s = { i };\n"
6069+
" g(&s);\n"
6070+
"}\n");
6071+
ASSERT_EQUALS("", errout.str());
6072+
}
6073+
60626074
void localvarstring1() { // ticket #1597
60636075
functionVariableUsage("void foo() {\n"
60646076
" std::string s;\n"

0 commit comments

Comments
 (0)