diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7fb9438a0..0f8db67e8 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3790,6 +3790,10 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty // check if type does not have a namespace if (typeTok->strAt(-1) != "::" && typeTok->strAt(1) != "::") { + // check if type same as scope + if (start->isClassOrStruct() && typeTok->str() == start->className) + return start->definedType; + while (scope) { // look for type in this scope const Type * type = scope->findType(typeTok->str()); diff --git a/test/testclass.cpp b/test/testclass.cpp index 744abb25a..f96606cc1 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -413,6 +413,14 @@ private: " return 0;\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #8600 + checkExplicitConstructors("struct A { struct B; };\n" + "struct A::B {\n" + " B() = default;\n" + " B(const B&) {}\n" + "};"); + ASSERT_EQUALS("", errout.str()); } void checkDuplInheritedMembers(const char code[]) { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 53ed4bd0d..2b4b52bf5 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -289,6 +289,7 @@ private: TEST_CASE(symboldatabase69); TEST_CASE(symboldatabase70); TEST_CASE(symboldatabase71); + TEST_CASE(symboldatabase72); // #8600 TEST_CASE(enum1); TEST_CASE(enum2); @@ -3925,6 +3926,21 @@ private: ASSERT(db && db->typeList.size() == 2); } + void symboldatabase72() { // #8600 + GET_SYMBOL_DB("struct A { struct B; };\n" + "struct A::B {\n" + " B() = default;\n" + " B(const B&) {}\n" + "};"); + + ASSERT(db && db->scopeList.size() == 4); + ASSERT(db && db->typeList.size() == 2); + const Token * f = db ? Token::findsimplematch(tokenizer.tokens(), "B ( const B & ) { }") : nullptr; + ASSERT(f != nullptr); + ASSERT(f && f->function() && f->function()->token->linenr() == 4); + ASSERT(f && f->function() && f->function()->type == Function::eCopyConstructor); + } + void enum1() { GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");