diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index d1ac96f2b..6e508b399 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -742,6 +742,11 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti for (std::list::iterator it = scopeList.begin(); it != scopeList.end(); ++it) { scope = &(*it); + if (!scope->definedType) { + _blankTypes.push_back(Type()); + scope->definedType = &_blankTypes.back(); + } + if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::Unknown) { // check for default constructor bool hasDefaultConstructor = false; @@ -799,7 +804,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti if (scope->definedType->needInitialization == Type::Unknown) unknowns++; } - } else if (scope->type == Scope::eUnion && scope->definedType && scope->definedType->needInitialization == Type::Unknown) + } else if (scope->type == Scope::eUnion && scope->definedType->needInitialization == Type::Unknown) scope->definedType->needInitialization = Type::True; } diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 0d7ed461f..03b7ad090 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -730,6 +730,9 @@ private: /** variable symbol table */ std::vector _variableList; + + /** list for missing types */ + std::list _blankTypes; }; #endif diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 321bcf3b2..a8ea3ab3a 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -193,6 +193,7 @@ private: TEST_CASE(symboldatabase33); // ticket #4682 (false negatives) TEST_CASE(symboldatabase34); // ticket #4694 (segmentation fault) TEST_CASE(symboldatabase35); // ticket #4806 (segmentation fault) + TEST_CASE(symboldatabase36); // ticket #4892 (segmentation fault) TEST_CASE(isImplicitlyVirtual); @@ -1513,6 +1514,11 @@ private: ASSERT_EQUALS("", errout.str()); } + void symboldatabase36() { // ticket #4892 + check("void struct ( ) { if ( 1 ) } int main ( ) { }"); + ASSERT_EQUALS("", errout.str()); + } + void isImplicitlyVirtual() { { GET_SYMBOL_DB("class Base {\n"