Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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% .")) {
Expand Down
12 changes: 12 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class TestUnusedVar : public TestFixture {
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);
Expand Down Expand Up @@ -6059,6 +6060,17 @@ class TestUnusedVar : public TestFixture {
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"
Expand Down