Skip to content

Commit 9528571

Browse files
authored
fix out of line member functions using global namespace (#3063)
1 parent 6012cd4 commit 9528571

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2724,7 +2724,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
27242724

27252725
// back up to head of path
27262726
while (tok1 && tok1->previous() && tok1->previous()->str() == "::" && tok1->tokAt(-2) &&
2727-
(tok1->tokAt(-2)->isName() ||
2727+
((tok1->tokAt(-2)->isName() && !tok1->tokAt(-2)->isStandardType()) ||
27282728
(tok1->strAt(-2) == ">" && tok1->linkAt(-2) && Token::Match(tok1->linkAt(-2)->previous(), "%name%")))) {
27292729
count++;
27302730
const Token * tok2 = tok1->tokAt(-2);
@@ -2745,6 +2745,12 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
27452745
if (!tok1)
27462746
return;
27472747

2748+
// add global namespace if present
2749+
if (tok1->strAt(-1) == "::") {
2750+
path_length++;
2751+
path.insert(0, ":: ");
2752+
}
2753+
27482754
std::list<Scope>::iterator it1;
27492755

27502756
// search for match

test/testsymboldatabase.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ class TestSymbolDatabase: public TestFixture {
399399
TEST_CASE(findFunction32); // C: relax type matching
400400
TEST_CASE(findFunction33); // #9885 variadic function
401401
TEST_CASE(findFunction34); // #10061
402+
TEST_CASE(findFunction35);
402403
TEST_CASE(findFunctionContainer);
403404
TEST_CASE(findFunctionExternC);
404405
TEST_CASE(findFunctionGlobalScope); // ::foo
@@ -6238,6 +6239,29 @@ class TestSymbolDatabase: public TestFixture {
62386239
ASSERT_EQUALS(8, foo->function()->tokenDef->linenr());
62396240
}
62406241

6242+
void findFunction35() {
6243+
GET_SYMBOL_DB("namespace clangimport {\n"
6244+
" class AstNode {\n"
6245+
" public:\n"
6246+
" AstNode();\n"
6247+
" void createTokens();\n"
6248+
" };\n"
6249+
"}\n"
6250+
"::clangimport::AstNode::AstNode() { }\n"
6251+
"void ::clangimport::AstNode::createTokens() { }");
6252+
(void)db;
6253+
const Token *foo = Token::findsimplematch(tokenizer.tokens(), "AstNode ( ) { }");
6254+
ASSERT(foo);
6255+
ASSERT(foo->function());
6256+
ASSERT(foo->function()->tokenDef);
6257+
ASSERT_EQUALS(4, foo->function()->tokenDef->linenr());
6258+
foo = Token::findsimplematch(tokenizer.tokens(), "createTokens ( ) { }");
6259+
ASSERT(foo);
6260+
ASSERT(foo->function());
6261+
ASSERT(foo->function()->tokenDef);
6262+
ASSERT_EQUALS(5, foo->function()->tokenDef->linenr());
6263+
}
6264+
62416265
void findFunctionContainer() {
62426266
{
62436267
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"

0 commit comments

Comments
 (0)