Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12761 (SymbolDatabase: two structs with same name, constructor added to the wrong struct in the SymbolDatabase) #6424

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6194,10 +6194,9 @@ const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope
if (tok->strAt(1) == "::") {
scope = scope->findRecordInNestedList(tok->str());
tok = tok->tokAt(2);
} else if (tok->strAt(1) == "<" && Token::simpleMatch(tok->linkAt(1), "> ::")) {
scope = scope->findRecordInNestedList(tok->str());
tok = tok->linkAt(1)->tokAt(2);
} else
} else if (tok->strAt(1) == "<")
return nullptr;
else
return scope->findRecordInNestedList(tok->str());
}

Expand Down
42 changes: 38 additions & 4 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(createSymbolDatabaseFindAllScopes5);
TEST_CASE(createSymbolDatabaseFindAllScopes6);
TEST_CASE(createSymbolDatabaseFindAllScopes7);
TEST_CASE(createSymbolDatabaseFindAllScopes8); // #12761

TEST_CASE(createSymbolDatabaseIncompleteVars);

Expand Down Expand Up @@ -5611,7 +5612,7 @@ class TestSymbolDatabase : public TestFixture {
"static const int foo = 8;\n"
"}\n");
ASSERT(db);
ASSERT_EQUALS(6, db->scopeList.size());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have double checked that the duplInheritedMember etc are not shown again that was supposed to be fixed when this test was added.

ASSERT_EQUALS(9, db->scopeList.size());
ASSERT_EQUALS(1, db->scopeList.front().varlist.size());
auto list = db->scopeList;
list.pop_front();
Expand Down Expand Up @@ -5658,12 +5659,12 @@ class TestSymbolDatabase : public TestFixture {
"};\n"
"const S S::IN(1);\n");
ASSERT(db);
ASSERT_EQUALS(6, db->scopeList.size());
ASSERT_EQUALS(7, db->scopeList.size());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have double checked that 11444 problems are not shown again.

const Token* const var = Token::findsimplematch(tokenizer.tokens(), "IN (");
ASSERT(var && var->variable());
ASSERT_EQUALS(var->variable()->name(), "IN");
auto it = db->scopeList.begin();
std::advance(it, 4);
auto it = db->scopeList.cbegin();
std::advance(it, 5);
ASSERT_EQUALS(it->className, "S");
ASSERT_EQUALS(var->variable()->scope(), &*it);
}
Expand Down Expand Up @@ -5754,6 +5755,39 @@ class TestSymbolDatabase : public TestFixture {
}
}

void createSymbolDatabaseFindAllScopes8() // #12761
{
// There are 2 myst constructors. They should belong to different scopes.
GET_SYMBOL_DB("template <class A = void, class B = void, class C = void>\n"
"class Test {\n"
"private:\n"
" template <class T>\n"
" struct myst {\n"
" T* x;\n"
" myst(T* y) : x(y){};\n" // <- myst constructor
" };\n"
"};\n"
"\n"
"template <class A, class B> class Test<A, B, void> {};\n"
"\n"
"template <>\n"
"class Test<void, void, void> {\n"
"private:\n"
" template <class T>\n"
" struct myst {\n"
" T* x;\n"
" myst(T* y) : x(y){};\n" // <- myst constructor
" };\n"
"};");
ASSERT(db);

const Token* myst1 = Token::findsimplematch(tokenizer.tokens(), "myst ( T * y )");
const Token* myst2 = Token::findsimplematch(myst1->next(), "myst ( T * y )");
ASSERT(myst1);
ASSERT(myst2);
ASSERT(myst1->scope() != myst2->scope());
}

void createSymbolDatabaseIncompleteVars()
{
{
Expand Down
Loading