Fixed SymbolDatabase if unnamed struct is casted and returned (#6125)

This commit is contained in:
PKEuS 2014-09-03 11:15:05 +02:00
parent bf2f76e70c
commit 6d27ca6c9a
2 changed files with 33 additions and 1 deletions

View File

@ -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();

View File

@ -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<Scope>::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"