SymbolDatabase: Improved function matching in C code

This commit is contained in:
Daniel Marjamäki 2020-11-04 07:17:17 +01:00
parent 198bbc8a5a
commit ae1b9cb14e
2 changed files with 17 additions and 1 deletions

View File

@ -4807,7 +4807,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
fallback1++;
// Try to evaluate the apparently more complex expression
else {
else if (check->isCPP()) {
const Token *vartok = arguments[j];
while (vartok->isUnaryOp("&") || vartok->isUnaryOp("*"))
vartok = vartok->astOperand1();
@ -4825,6 +4825,10 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
break;
}
}
else
// C code: if number of arguments match then do not match types
fallback1++;
}
const size_t hasToBe = func->isVariadic() ? (func->argCount() - 1) : args;

View File

@ -378,6 +378,7 @@ private:
TEST_CASE(findFunction29);
TEST_CASE(findFunction30);
TEST_CASE(findFunction31);
TEST_CASE(findFunction32); // C: relax type matching
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
@ -6179,6 +6180,17 @@ private:
ASSERT_EQUALS(1, foo->function()->tokenDef->linenr());
}
void findFunction32() {
GET_SYMBOL_DB_C("void foo(char *p);\n"
"void bar() { foo(\"123\"); }");
(void)db;
const Token *foo = Token::findsimplematch(tokenizer.tokens(), "foo ( \"123\" ) ;");
ASSERT(foo);
ASSERT(foo->function());
ASSERT(foo->function()->tokenDef);
ASSERT_EQUALS(1, foo->function()->tokenDef->linenr());
}
void findFunctionContainer() {
{
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"