diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a7dd01546..b2e2c52d4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1975,7 +1975,11 @@ Scope::Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_) : type = Scope::eGlobal; } else if (classDef->str() == "class") { type = Scope::eClass; - className = classDef->next()->str(); + // skip over qualification if present + const Token *nameTok = classDef->next(); + while (nameTok && Token::Match(nameTok, "%type% ::")) + nameTok = nameTok->tokAt(2); + className = nameTok->str(); } else if (classDef->str() == "struct") { type = Scope::eStruct; // anonymous and unnamed structs don't have a name diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 27bb0203d..52db57b8d 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -61,6 +61,7 @@ private: TEST_CASE(simple6); // ticket #4085 - uninstantiated template class TEST_CASE(simple7); // ticket #4531 TEST_CASE(simple8); + TEST_CASE(simple9); // ticket #4574 TEST_CASE(initvar_with_this); // BUG 2190300 TEST_CASE(initvar_if); // BUG 2190290 @@ -320,6 +321,16 @@ private: "[test.cpp:3]: (style) The class 'Wilma' does not have a constructor.\n", errout.str()); } + void simple9() { // ticket #4574 + check("class Unknown::Fred {\n" + "public:\n" + " Fred() : x(0) { }\n" + "private:\n" + " int x;\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void initvar_with_this() { check("struct Fred\n" "{\n"