Skip to content

Commit baedd07

Browse files
committed
Fix #14661 Regression while handling arrays of function pointers
Regression introduced in PR cppcheck-opensource#8402.
1 parent b599bb4 commit baedd07

2 files changed

Lines changed: 10 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::simpleMatch(defValTok, ") ("))
742744
defValTok = defValTok->linkAt(1)->next();
743745
for (; defValTok; defValTok = defValTok->next()) {
744746
if (defValTok->str() == "[")

test/testunusedvar.cpp

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

70397046
void localvarAddr() { // #7747

0 commit comments

Comments
 (0)