diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 69d6c3dc0b6..924734cae4d 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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()); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 2b37bf04486..f096a195f07 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -430,6 +430,7 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(createSymbolDatabaseFindAllScopes5); TEST_CASE(createSymbolDatabaseFindAllScopes6); TEST_CASE(createSymbolDatabaseFindAllScopes7); + TEST_CASE(createSymbolDatabaseFindAllScopes8); // #12761 TEST_CASE(createSymbolDatabaseIncompleteVars); @@ -5611,7 +5612,7 @@ class TestSymbolDatabase : public TestFixture { "static const int foo = 8;\n" "}\n"); ASSERT(db); - ASSERT_EQUALS(6, db->scopeList.size()); + ASSERT_EQUALS(9, db->scopeList.size()); ASSERT_EQUALS(1, db->scopeList.front().varlist.size()); auto list = db->scopeList; list.pop_front(); @@ -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()); 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); } @@ -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 \n" + "class Test {\n" + "private:\n" + " template \n" + " struct myst {\n" + " T* x;\n" + " myst(T* y) : x(y){};\n" // <- myst constructor + " };\n" + "};\n" + "\n" + "template class Test {};\n" + "\n" + "template <>\n" + "class Test {\n" + "private:\n" + " template \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() { {