Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Feb 12, 2024
1 parent 40552e2 commit d822de0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,12 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
} else {
tok = tok->link();
}
} else if (Token::Match(tok, "%name% (")) {
} else if (Token::Match(tok, "extern %type%")) {
while (Token::Match(tok, "%name%|*|&"))
tok = tok->next();
if (tok->str() != "(")
continue;
tok = tok->previous();
if (Token::simpleMatch(tok->linkAt(1), ") ;")) {
const Token *funcStart = nullptr;
const Token *argStart = nullptr;
Expand All @@ -760,7 +765,6 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
tok = declEnd;
}
}
continue;
}
}
}
Expand Down Expand Up @@ -5930,8 +5934,7 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const
const Scope *currScope = tok->scope();
while (currScope && currScope->isExecutable()) {
if (const Function* f = currScope->findFunction(tok)) {
if (f->isExtern())
return f;
return f;
}
if (currScope->functionOf)
currScope = currScope->functionOf;
Expand Down
16 changes: 15 additions & 1 deletion test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(memberFunctionOfUnknownClassMacro2);
TEST_CASE(memberFunctionOfUnknownClassMacro3);
TEST_CASE(functionLinkage);
TEST_CASE(externalFunctionsInsideAFunction); // #12420
TEST_CASE(externalFunctionsInsideAFunction); // #12420
TEST_CASE(namespacedFunctionInsideExternBlock); // #12420

TEST_CASE(classWithFriend);

Expand Down Expand Up @@ -2378,6 +2379,19 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(call && call->function() == f->function());
}

void namespacedFunctionInsideExternBlock() {
GET_SYMBOL_DB("namespace N {\n"
" void f();\n"
"}\n"
"extern \"C\" {\n"
" void f() {\n"
" N::f();\n"
" }\n"
"}\n");

ASSERT(db && errout.str().empty());
}

void classWithFriend() {
GET_SYMBOL_DB("class Foo {}; class Bar1 { friend class Foo; }; class Bar2 { friend Foo; };");
// 3 scopes: Global, 3 classes
Expand Down

0 comments on commit d822de0

Please sign in to comment.