diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 9d280b4a3..871d67cda 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -192,7 +192,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() continue; else if (Token::Match(tok2, "%name% (") && mTokenizer->isFunctionHead(tok2->next(), "{;")) continue; - else if (Token::Match(tok2, "%name% [")) + else if (Token::Match(tok2, "%name% [|=")) continue; // skip template else if (Token::simpleMatch(tok2, ";") && diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3d4cc39a4..5d4e91841 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1371,7 +1371,7 @@ void Tokenizer::simplifyTypedef() structRemoved = true; typeStart = typeStart->next(); } - if (Token::Match(typeStart, "struct|class") && Token::Match(tok2, "%name% ::")) + if (Token::Match(typeStart, "struct|class|union") && Token::Match(tok2, "%name% ::")) typeStart = typeStart->next(); if (sameStartEnd) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 787e69115..380301497 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -658,7 +658,7 @@ private: } void garbageCode43() { // #6703 - ASSERT_THROW(checkCode("int { }; struct A a = { }"), InternalError); + checkCode("int { }; struct A a = { }"); } void garbageCode44() { // #6704 diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 6e808ebac..475e45627 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -356,6 +356,7 @@ private: TEST_CASE(symboldatabase95); // #10295 TEST_CASE(symboldatabase96); // #10126 TEST_CASE(symboldatabase97); // #10598 - final class + TEST_CASE(symboldatabase98); // #10451 TEST_CASE(createSymbolDatabaseFindAllScopes1); TEST_CASE(createSymbolDatabaseFindAllScopes2); @@ -4858,6 +4859,26 @@ private: ASSERT_EQUALS(functok->function()->type, Function::Type::eConstructor); } + void symboldatabase98() { // #10451 + { + GET_SYMBOL_DB("struct A { typedef struct {} B; };\n" + "void f() {\n" + " auto g = [](A::B b) -> void { A::B b2 = b; };\n" + "};\n"); + ASSERT(db); + ASSERT_EQUALS(5, db->scopeList.size()); + } + { + GET_SYMBOL_DB("typedef union {\n" + " int i;\n" + "} U;\n" + "template \n" + "void f();\n"); + ASSERT(db); + ASSERT_EQUALS(2, db->scopeList.size()); + } + } + void createSymbolDatabaseFindAllScopes1() { GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }"); ASSERT(db->scopeList.size() == 3);