Skip to content

Commit

Permalink
Fix #12209 "debug: Executable scope 'x' with unknown function." with …
Browse files Browse the repository at this point in the history
…anonymous namespace (danmar#5688)
  • Loading branch information
chrchr-github committed Nov 20, 2023
1 parent f9521cf commit f5630e7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3254,7 +3254,8 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
}
}

if (scope1->className == tok1->str() && (scope1->type != Scope::eFunction)) {
const bool isAnonymousNamespace = (scope1->type == Scope::eNamespace && scope1->className.empty());
if ((scope1->className == tok1->str() && (scope1->type != Scope::eFunction)) || isAnonymousNamespace) {
// do the scopes match (same scope) or do their names match (multiple namespaces)
if ((*scope == scope1->nestedIn) || (*scope &&
(*scope)->className == scope1->nestedIn->className &&
Expand Down Expand Up @@ -3286,6 +3287,8 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
tok1 = tok1->tokAt(2);
scope2 = scope2->findRecordInNestedList(tok1->str());
}
if (isAnonymousNamespace)
scope2 = scope2->findRecordInNestedList(tok1->str());

if (count == 1 && scope2) {
match = true;
Expand Down
26 changes: 26 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(createSymbolDatabaseFindAllScopes4);
TEST_CASE(createSymbolDatabaseFindAllScopes5);
TEST_CASE(createSymbolDatabaseFindAllScopes6);
TEST_CASE(createSymbolDatabaseFindAllScopes7);

TEST_CASE(createSymbolDatabaseIncompleteVars);

Expand Down Expand Up @@ -5461,6 +5462,31 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(classNC.derivedFrom[1].type, &classNB);
}

void createSymbolDatabaseFindAllScopes7()
{
GET_SYMBOL_DB("namespace {\n"
" struct S {\n"
" void f();\n"
" };\n"
"}\n"
"void S::f() {}\n");
ASSERT(db);
ASSERT_EQUALS(4, db->scopeList.size());
auto anon = db->scopeList.begin();
++anon;
ASSERT(anon->className.empty());
ASSERT_EQUALS(anon->type, Scope::eNamespace);
auto S = anon;
++S;
ASSERT_EQUALS(S->type, Scope::eStruct);
ASSERT_EQUALS(S->className, "S");
ASSERT_EQUALS(S->nestedIn, &*anon);
const Token* f = Token::findsimplematch(tokenizer.tokens(), "f ( ) {");
ASSERT(f && f->function() && f->function()->functionScope && f->function()->functionScope->bodyStart);
ASSERT_EQUALS(f->function()->functionScope->functionOf, &*S);
ASSERT_EQUALS(f->function()->functionScope->bodyStart->linenr(), 6);
}

void createSymbolDatabaseIncompleteVars()
{
{
Expand Down

0 comments on commit f5630e7

Please sign in to comment.