diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 749501c40..3d963adff 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -765,7 +765,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti scopeList.push_back(Scope(this, tok->linkAt(-1)->linkAt(-1), scope, Scope::eLambda, tok)); scope->nestedList.push_back(&scopeList.back()); scope = &scopeList.back(); - } else if (!Token::Match(tok->previous(), "=|,|(|return")) { + } else if (!Token::Match(tok->previous(), "=|,|(|return") && !(tok->strAt(-1) == ")" && Token::Match(tok->linkAt(-1)->previous(), "=|,|(|return"))) { scopeList.push_back(Scope(this, tok, scope, Scope::eUnconditional, tok)); scope->nestedList.push_back(&scopeList.back()); scope = &scopeList.back(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 95a2947f6..9a0118df6 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -224,6 +224,7 @@ private: TEST_CASE(symboldatabase42); // only put variables in variable list TEST_CASE(symboldatabase43); // #4738 TEST_CASE(symboldatabase44); + TEST_CASE(symboldatabase45); // #6125 TEST_CASE(isImplicitlyVirtual); @@ -1926,6 +1927,37 @@ private: ASSERT(db->getVariableFromVarId(i) != nullptr); } + void symboldatabase45() { + GET_SYMBOL_DB("typedef struct {\n" + " unsigned long bits;\n" + "} S;\n" + "struct T {\n" + " S span;\n" + " int flags;\n" + "};\n" + "struct T f(int x) {\n" + " return (struct T) {\n" + " .span = (S) { 0UL },\n" + " .flags = (x ? 256 : 0),\n" + " };\n" + "}"); + + ASSERT(db != nullptr); + ASSERT_EQUALS(4U, db->getVariableListSize() - 1); + for (std::size_t i = 1U; i < db->getVariableListSize(); i++) + ASSERT(db->getVariableFromVarId(i) != nullptr); + + ASSERT_EQUALS(4U, db->scopeList.size()); + std::list::const_iterator scope = db->scopeList.begin(); + ASSERT_EQUALS(Scope::eGlobal, scope->type); + ++scope; + ASSERT_EQUALS(Scope::eStruct, scope->type); + ++scope; + ASSERT_EQUALS(Scope::eStruct, scope->type); + ++scope; + ASSERT_EQUALS(Scope::eFunction, scope->type); + } + void isImplicitlyVirtual() { { GET_SYMBOL_DB("class Base {\n"