SymbolDatabase: look for functions in anonymous namespaces in the findFunction

This commit is contained in:
Daniel Marjamäki 2019-10-01 19:09:34 +02:00
parent 07b337c580
commit cf965b72b5
2 changed files with 26 additions and 6 deletions

View File

@ -4233,13 +4233,24 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
// find all the possible functions that could match
const std::size_t args = arguments.size();
for (std::multimap<std::string, const Function *>::const_iterator it = functionMap.find(tok->str()); it != functionMap.cend() && it->first == tok->str(); ++it) {
const Function *func = it->second;
if (args == func->argCount() ||
(func->isVariadic() && args >= (func->argCount() - 1)) ||
(args < func->argCount() && args >= func->minArgCount())) {
matches.push_back(func);
auto addMatchingFunctions = [&](const Scope *scope) {
for (std::multimap<std::string, const Function *>::const_iterator it = scope->functionMap.find(tok->str()); it != scope->functionMap.cend() && it->first == tok->str(); ++it) {
const Function *func = it->second;
if (args == func->argCount() ||
(func->isVariadic() && args >= (func->argCount() - 1)) ||
(args < func->argCount() && args >= func->minArgCount())) {
matches.push_back(func);
}
}
};
addMatchingFunctions(this);
// check in anonumous namespaces
for (const Scope *nestedScope : nestedList) {
if (nestedScope->type == eNamespace && nestedScope->className.empty())
addMatchingFunctions(nestedScope);
}
// check in base classes

View File

@ -344,6 +344,7 @@ private:
TEST_CASE(findFunction24); // smart pointer
TEST_CASE(findFunction25); // std::vector<std::shared_ptr<Fred>>
TEST_CASE(findFunction26); // #8668 - pointer parameter in function call, const pointer function argument
TEST_CASE(findFunction27);
TEST_CASE(findFunctionContainer);
TEST_CASE(valueTypeMatchParameter); // ValueType::matchParameter
@ -5568,6 +5569,14 @@ private:
ASSERT(dostuff1->function() && dostuff1->function()->token && dostuff1->function()->token->linenr() == 1);
}
void findFunction27() {
GET_SYMBOL_DB("namespace { void a(int); }\n"
"void f() { a(9); }");
const Token *a = Token::findmatch(tokenizer.tokens(), "a ( 9 )");
ASSERT(a);
ASSERT(a->function());
}
void findFunctionContainer() {
{
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"