diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 04dd96477..e2ec9df79 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -345,7 +345,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // unnamed struct and union else if (Token::Match(tok, "struct|union {") && - Token::Match(tok->next()->link(), "} *|&| %name% ;|[")) { + Token::Match(tok->next()->link(), "} *|&| %name% ;|[|=")) { scopeList.emplace_back(this, tok, scope); Scope *new_scope = &scopeList.back(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 4aead430e..c038e1cf8 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -295,6 +295,8 @@ private: TEST_CASE(symboldatabase72); // #8600 TEST_CASE(symboldatabase73); // #8603 + TEST_CASE(createSymbolDatabaseFindAllScopes1); + TEST_CASE(enum1); TEST_CASE(enum2); TEST_CASE(enum3); @@ -4045,6 +4047,12 @@ private: ASSERT_EQUALS(3, f2->function->token->linenr()); } + void createSymbolDatabaseFindAllScopes1() { + GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }"); + ASSERT(db->scopeList.size() == 3); + ASSERT_EQUALS(Scope::eUnion, db->scopeList.back().type); + } + void enum1() { GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");