Fix some new SymbolDatabase bailout; unhandled code syntax errors. (#1152)

This commit is contained in:
IOBYTE 2018-04-06 15:32:32 -04:00 committed by Daniel Marjamäki
parent 05acf9b352
commit 7e15e39f39
2 changed files with 20 additions and 2 deletions

View File

@ -83,8 +83,10 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
"SymbolDatabase",
tok->progressValue());
// Locate next class
if ((_tokenizer->isCPP() && ((Token::Match(tok, "class|struct|union|namespace ::| %name% {|:|::|<") && tok->strAt(-1) != "friend") ||
(Token::Match(tok, "enum class| %name% {") || Token::Match(tok, "enum class| %name% : %name% {"))))
if ((_tokenizer->isCPP() && ((Token::Match(tok, "class|struct|union|namespace ::| %name% {|:|::|<") &&
!Token::Match(tok->previous(), "new|friend|)|(")) ||
(Token::Match(tok, "enum class| %name% {") ||
Token::Match(tok, "enum class| %name% : %name% {"))))
|| (_tokenizer->isC() && Token::Match(tok, "struct|union|enum %name% {"))) {
const Token *tok2 = tok->tokAt(2);

View File

@ -272,6 +272,7 @@ private:
TEST_CASE(symboldatabase58); // #6985 (using namespace type lookup)
TEST_CASE(symboldatabase59);
TEST_CASE(symboldatabase60);
TEST_CASE(symboldatabase61);
TEST_CASE(enum1);
TEST_CASE(enum2);
@ -2896,6 +2897,21 @@ private:
ASSERT(db && db->scopeList.size() == 2);
}
void symboldatabase61() {
GET_SYMBOL_DB("struct Fred {\n"
" struct Info { };\n"
"};\n"
"void foo() {\n"
" struct Fred::Info* info;\n"
" info = new (nothrow) struct Fred::Info();\n"
" info = new struct Fred::Info();\n"
" memset(info, 0, sizeof(struct Fred::Info));\n"
"}");
ASSERT(db != nullptr);
ASSERT(db && db->scopeList.size() == 4);
}
void enum1() {
GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");