SymbolDatabase: Improved lookup of function calls
This commit is contained in:
parent
3e5ed59a85
commit
e4a70f87e6
|
@ -4021,6 +4021,15 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
|
|||
}
|
||||
}
|
||||
|
||||
// using namespace..
|
||||
for (const Scope *scope = this; scope; scope = scope->nestedIn) {
|
||||
for (const UsingInfo &usingInfo : scope->usingList) {
|
||||
const Function *func = usingInfo.scope->findFunction(tok,requireConst);
|
||||
if (func)
|
||||
matches.push_back(func);
|
||||
}
|
||||
}
|
||||
|
||||
// check in base classes
|
||||
findFunctionInBase(tok->str(), args, matches);
|
||||
|
||||
|
|
|
@ -325,6 +325,7 @@ private:
|
|||
TEST_CASE(findFunction18);
|
||||
TEST_CASE(findFunction19);
|
||||
TEST_CASE(findFunction20); // #8280
|
||||
TEST_CASE(findFunction21); // #8592 - using namespace
|
||||
|
||||
TEST_CASE(noexceptFunction1);
|
||||
TEST_CASE(noexceptFunction2);
|
||||
|
@ -5158,6 +5159,30 @@ private:
|
|||
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 12);
|
||||
}
|
||||
|
||||
void findFunction21() { // using namespace ..
|
||||
{
|
||||
GET_SYMBOL_DB("namespace NS { void f(); };\n"
|
||||
"void foo() {\n"
|
||||
" using namespace NS;\n"
|
||||
" f();\n"
|
||||
"}");
|
||||
const Scope *foo = db->findScopeByName("foo");
|
||||
const Token *ftok = Token::findsimplematch(foo->bodyStart, "f (");
|
||||
ASSERT(foo->findFunction(ftok,false));
|
||||
}
|
||||
|
||||
{
|
||||
GET_SYMBOL_DB("namespace NS { void f(); };\n"
|
||||
"void foo() {\n"
|
||||
" using namespace NS;\n"
|
||||
" if (abc) { f(); }\n"
|
||||
"}");
|
||||
const Scope *foo = db->findScopeByName("foo");
|
||||
const Token *ftok = Token::findsimplematch(foo->bodyStart, "f (");
|
||||
ASSERT(foo->findFunction(ftok,false));
|
||||
}
|
||||
}
|
||||
|
||||
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
|
||||
ASSERT_EQUALS(true, x != nullptr); \
|
||||
if (x) ASSERT_EQUALS(true, x->isNoExcept());
|
||||
|
|
Loading…
Reference in New Issue