Skip to content

Commit 328cb0f

Browse files
committed
Fix regression while handling arrays of function pointers
Regression introduced in PR #8402.
1 parent b599bb4 commit 328cb0f

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/checkunusedvar.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
738738
if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken()))
739739
continue;
740740
const Token* defValTok = i->nameToken()->next();
741-
if (Token::Match(i->nameToken()->previous(), "* %var% ) (")) // function pointer. Jump behind parameter list.
741+
while (defValTok && defValTok->str() == "[")
742+
defValTok = defValTok->link()->next();
743+
if (Token::Match(defValTok, ") ("))
742744
defValTok = defValTok->linkAt(1)->next();
743745
for (; defValTok; defValTok = defValTok->next()) {
744746
if (defValTok->str() == "[")

test/testunusedvar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7034,6 +7034,12 @@ class TestUnusedVar : public TestFixture {
70347034
" funcPtr();\n"
70357035
"}");
70367036
ASSERT_EQUALS("", errout_str());
7037+
7038+
functionVariableUsage("int main() {\n"
7039+
" void (*const funcPtr[])(void) = {x};\n"
7040+
" funcPtr[0]();\n"
7041+
"}");
7042+
ASSERT_EQUALS("", errout_str());
70377043
}
70387044

70397045
void localvarAddr() { // #7747

0 commit comments

Comments
 (0)