From 03c3674094278ef769316e600b6b49b1c0c862c3 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 14 Mar 2022 15:03:28 +0100 Subject: [PATCH] Don't insert union into template argument list, add test --- lib/tokenize.cpp | 2 +- test/testsymboldatabase.cpp | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) 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/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 3877432ec..793900668 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -4860,17 +4860,23 @@ private: } 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(3, db->scopeList.size()); - - const Token *functok = Token::findmatch(tokenizer.tokens(), "%name% ("); - ASSERT(functok); - ASSERT(functok->function()); - ASSERT_EQUALS(functok->function()->type, Function::Type::eConstructor); + { + 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() {