SymbolDatabase: Fix handling of function pointer arguments

This commit is contained in:
Daniel Marjamäki 2023-02-27 15:10:25 +01:00
parent 65fc31cba9
commit 80050b11dd
2 changed files with 12 additions and 2 deletions

View File

@ -4151,10 +4151,10 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
nameTok = tok->tokAt(2); nameTok = tok->tokAt(2);
endTok = nameTok->previous(); endTok = nameTok->previous();
tok = tok->link(); tok = tok->link();
} else if (tok != startTok && !nameTok && Token::Match(tok, "( * %var% ) ( ) [,)]")) { } else if (tok != startTok && !nameTok && Token::Match(tok, "( * %var% ) (") && Token::Match(tok->link()->linkAt(1), ") [,)]")) {
nameTok = tok->tokAt(2); nameTok = tok->tokAt(2);
endTok = nameTok->previous(); endTok = nameTok->previous();
tok = tok->link()->tokAt(2); tok = tok->link()->linkAt(1);
} else if (tok != startTok && !nameTok && Token::Match(tok, "( * %var% ) [")) { } else if (tok != startTok && !nameTok && Token::Match(tok, "( * %var% ) [")) {
nameTok = tok->tokAt(2); nameTok = tok->tokAt(2);
endTok = nameTok->previous(); endTok = nameTok->previous();

View File

@ -254,6 +254,7 @@ private:
TEST_CASE(functionArgs16); // #9591 TEST_CASE(functionArgs16); // #9591
TEST_CASE(functionArgs17); TEST_CASE(functionArgs17);
TEST_CASE(functionArgs18); // #10376 TEST_CASE(functionArgs18); // #10376
TEST_CASE(functionArgs19); // #10376
TEST_CASE(functionImplicitlyVirtual); TEST_CASE(functionImplicitlyVirtual);
@ -2670,6 +2671,15 @@ private:
ASSERT_EQUALS(2, func->argCount()); ASSERT_EQUALS(2, func->argCount());
} }
void functionArgs19() {
const char code[] = "void f(int (*fp)(int), int x, int y) {}";
GET_SYMBOL_DB(code);
ASSERT(db != nullptr);
const Scope *scope = db->functionScopes.front();
const Function *func = scope->function;
ASSERT_EQUALS(3, func->argCount());
}
void functionImplicitlyVirtual() { void functionImplicitlyVirtual() {
GET_SYMBOL_DB("class base { virtual void f(); };\n" GET_SYMBOL_DB("class base { virtual void f(); };\n"
"class derived : base { void f(); };\n" "class derived : base { void f(); };\n"