diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 3c496ede1..fc6910582 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -212,12 +212,13 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke } if (level > 0) { errorToken=tok; + syntaxError(tok); return true; } } } - return 0; + return false; } unsigned int TemplateSimplifier::templateParameters(const Token *tok) @@ -1421,7 +1422,7 @@ void TemplateSimplifier::simplifyTemplates( templates2.push_back(*iter1); } - for (std::list::iterator it = templates2.begin(); it != templates2.end(); ++it) { + for (std::list::const_iterator it = templates2.begin(); it != templates2.end(); ++it) { std::list::iterator it1 = std::find(templates.begin(), templates.end(), *it); if (it1 != templates.end()) { templates.erase(it1); @@ -1430,3 +1431,8 @@ void TemplateSimplifier::simplifyTemplates( } } } + +void TemplateSimplifier::syntaxError(const Token *tok) +{ + throw InternalError(tok, "syntax error", InternalError::SYNTAX); +} diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 4dbbe6bcc..66abf017b 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -187,6 +187,9 @@ private: */ static bool removeTemplate(Token *tok); + /** Syntax error */ + static void syntaxError(const Token *tok); + }; /// @} diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fd8ddc36d..39ab327e5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -973,14 +973,12 @@ void Tokenizer::simplifyTypedef() argEnd = tokOffset->link(); argFuncRetStart = argEnd->tokAt(2); - if (!argFuncRetStart) - { + if (!argFuncRetStart) { syntaxError(tokOffset); return; } argFuncRetEnd = argFuncRetStart->link(); - if (!argFuncRetEnd) - { + if (!argFuncRetEnd) { syntaxError(tokOffset); return; } @@ -994,14 +992,12 @@ void Tokenizer::simplifyTypedef() argEnd = tokOffset->link(); argFuncRetStart = argEnd->tokAt(2); - if (!argFuncRetStart) - { + if (!argFuncRetStart) { syntaxError(tokOffset); return; } argFuncRetEnd = argFuncRetStart->link(); - if (!argFuncRetEnd) - { + if (!argFuncRetEnd) { syntaxError(tokOffset); return; } @@ -7537,8 +7533,10 @@ void Tokenizer::simplifyEnum() ++classLevel; } else if (tok->str() == "enum") { Token *temp = tok->next(); - if (!temp) + if (!temp) { + syntaxError(tok); break; + } if (Token::Match(temp, "class|struct")) temp = temp->next(); if (!temp) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index cdbd55853..dd523a604 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3278,8 +3278,7 @@ private: void enum26() { // ticket #2975 (segmentation fault) const char code[] = "enum E {} e enum\n"; - checkSimplifyEnum(code); - ASSERT_EQUALS("", errout.str()); + ASSERT_THROW(checkSimplifyEnum(code), InternalError); } void enum27() { // ticket #3005 (segmentation fault)