Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5549,7 +5549,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const

//---------------------------------------------------------------------------

const Function* SymbolDatabase::findFunction(const Token *tok) const
const Function* SymbolDatabase::findFunction(const Token* const tok) const
{
// find the scope this function is in
const Scope *currScope = tok->scope();
Expand Down Expand Up @@ -5665,6 +5665,18 @@ const Function* SymbolDatabase::findFunction(const Token *tok) const
return func;
currScope = currScope->nestedIn;
}
// check using namespace
currScope = tok->scope();
while (currScope) {
for (const auto& ul : currScope->usingList) {
if (ul.scope) {
const Function* func = ul.scope->findFunction(tok);
if (func)
return func;
}
}
currScope = currScope->nestedIn;
}
}
// Check for constructor
if (Token::Match(tok, "%name% (|{")) {
Expand Down
34 changes: 33 additions & 1 deletion test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction45);
TEST_CASE(findFunction46);
TEST_CASE(findFunction47);
TEST_CASE(findFunction48);
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
Expand Down Expand Up @@ -7155,7 +7156,38 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
}

void findFunction47() {
void findFunction47() { // #8592
{
GET_SYMBOL_DB("namespace N {\n"
" void toupper(std::string& str);\n"
"}\n"
"void f(std::string s) {\n"
" using namespace N;\n"
" toupper(s);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "toupper ( s");
ASSERT(functok && functok->function());
ASSERT(functok->function()->name() == "toupper");
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
}
{
GET_SYMBOL_DB("namespace N {\n"
" void toupper(std::string& str);\n"
"}\n"
"using namespace N;\n"
"void f(std::string s) {\n"
" toupper(s);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "toupper ( s");
ASSERT(functok && functok->function());
ASSERT(functok->function()->name() == "toupper");
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
}
}

void findFunction48() {
GET_SYMBOL_DB("struct S {\n"
" S() {}\n"
" std::list<S> l;\n"
Expand Down