SymbolDatabase: look for functions in anonymous namespaces in the findFunction
This commit is contained in:
parent
07b337c580
commit
cf965b72b5
|
@ -4233,13 +4233,24 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
|
||||||
|
|
||||||
// find all the possible functions that could match
|
// find all the possible functions that could match
|
||||||
const std::size_t args = arguments.size();
|
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;
|
auto addMatchingFunctions = [&](const Scope *scope) {
|
||||||
if (args == func->argCount() ||
|
for (std::multimap<std::string, const Function *>::const_iterator it = scope->functionMap.find(tok->str()); it != scope->functionMap.cend() && it->first == tok->str(); ++it) {
|
||||||
(func->isVariadic() && args >= (func->argCount() - 1)) ||
|
const Function *func = it->second;
|
||||||
(args < func->argCount() && args >= func->minArgCount())) {
|
if (args == func->argCount() ||
|
||||||
matches.push_back(func);
|
(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
|
// check in base classes
|
||||||
|
|
|
@ -344,6 +344,7 @@ private:
|
||||||
TEST_CASE(findFunction24); // smart pointer
|
TEST_CASE(findFunction24); // smart pointer
|
||||||
TEST_CASE(findFunction25); // std::vector<std::shared_ptr<Fred>>
|
TEST_CASE(findFunction25); // std::vector<std::shared_ptr<Fred>>
|
||||||
TEST_CASE(findFunction26); // #8668 - pointer parameter in function call, const pointer function argument
|
TEST_CASE(findFunction26); // #8668 - pointer parameter in function call, const pointer function argument
|
||||||
|
TEST_CASE(findFunction27);
|
||||||
TEST_CASE(findFunctionContainer);
|
TEST_CASE(findFunctionContainer);
|
||||||
|
|
||||||
TEST_CASE(valueTypeMatchParameter); // ValueType::matchParameter
|
TEST_CASE(valueTypeMatchParameter); // ValueType::matchParameter
|
||||||
|
@ -5568,6 +5569,14 @@ private:
|
||||||
ASSERT(dostuff1->function() && dostuff1->function()->token && dostuff1->function()->token->linenr() == 1);
|
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() {
|
void findFunctionContainer() {
|
||||||
{
|
{
|
||||||
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
|
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
|
||||||
|
|
Loading…
Reference in New Issue