fix out of line member functions using global namespace (#3063)
This commit is contained in:
parent
6012cd4fd9
commit
952857195b
|
@ -2724,7 +2724,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
|
|||
|
||||
// back up to head of path
|
||||
while (tok1 && tok1->previous() && tok1->previous()->str() == "::" && tok1->tokAt(-2) &&
|
||||
(tok1->tokAt(-2)->isName() ||
|
||||
((tok1->tokAt(-2)->isName() && !tok1->tokAt(-2)->isStandardType()) ||
|
||||
(tok1->strAt(-2) == ">" && tok1->linkAt(-2) && Token::Match(tok1->linkAt(-2)->previous(), "%name%")))) {
|
||||
count++;
|
||||
const Token * tok2 = tok1->tokAt(-2);
|
||||
|
@ -2745,6 +2745,12 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
|
|||
if (!tok1)
|
||||
return;
|
||||
|
||||
// add global namespace if present
|
||||
if (tok1->strAt(-1) == "::") {
|
||||
path_length++;
|
||||
path.insert(0, ":: ");
|
||||
}
|
||||
|
||||
std::list<Scope>::iterator it1;
|
||||
|
||||
// search for match
|
||||
|
|
|
@ -399,6 +399,7 @@ private:
|
|||
TEST_CASE(findFunction32); // C: relax type matching
|
||||
TEST_CASE(findFunction33); // #9885 variadic function
|
||||
TEST_CASE(findFunction34); // #10061
|
||||
TEST_CASE(findFunction35);
|
||||
TEST_CASE(findFunctionContainer);
|
||||
TEST_CASE(findFunctionExternC);
|
||||
TEST_CASE(findFunctionGlobalScope); // ::foo
|
||||
|
@ -6238,6 +6239,29 @@ private:
|
|||
ASSERT_EQUALS(8, foo->function()->tokenDef->linenr());
|
||||
}
|
||||
|
||||
void findFunction35() {
|
||||
GET_SYMBOL_DB("namespace clangimport {\n"
|
||||
" class AstNode {\n"
|
||||
" public:\n"
|
||||
" AstNode();\n"
|
||||
" void createTokens();\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"::clangimport::AstNode::AstNode() { }\n"
|
||||
"void ::clangimport::AstNode::createTokens() { }");
|
||||
(void)db;
|
||||
const Token *foo = Token::findsimplematch(tokenizer.tokens(), "AstNode ( ) { }");
|
||||
ASSERT(foo);
|
||||
ASSERT(foo->function());
|
||||
ASSERT(foo->function()->tokenDef);
|
||||
ASSERT_EQUALS(4, foo->function()->tokenDef->linenr());
|
||||
foo = Token::findsimplematch(tokenizer.tokens(), "createTokens ( ) { }");
|
||||
ASSERT(foo);
|
||||
ASSERT(foo->function());
|
||||
ASSERT(foo->function()->tokenDef);
|
||||
ASSERT_EQUALS(5, foo->function()->tokenDef->linenr());
|
||||
}
|
||||
|
||||
void findFunctionContainer() {
|
||||
{
|
||||
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
|
||||
|
|
Loading…
Reference in New Issue