diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d24dc1db9..ddbf746dc 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -819,7 +819,7 @@ void CheckClass::initializationListUsage() const Variable* var = tok->variable(); if (var && var->scope() == owner && !var->isStatic()) { bool allowed = true; - for (const Token* tok2 = tok->tokAt(2); tok2->str() != ";"; tok2 = tok2->next()) { + for (const Token* tok2 = tok->tokAt(2); tok2 && tok2->str() != ";"; tok2 = tok2->next()) { if (tok2->varId()) { const Variable* var2 = tok2->variable(); if (var2 && var2->scope() == owner && diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 84156ddf0..7784a6d11 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -128,7 +128,6 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke tok = tok->link(); if (!tok) return true; - } // skip executing scopes.. const Token *start = Tokenizer::startOfExecutableScope(tok); @@ -212,8 +211,8 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke } } if (level > 0) { -// syntaxError(tok); - return tok; + errorToken=tok; + return true; } } } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 45a98e1ed..97cdb4834 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7520,6 +7520,8 @@ void Tokenizer::simplifyEnum() break; if (Token::Match(temp, "class|struct")) temp = temp->next(); + if (!temp) + break; if (!Token::Match(temp, "[{:]") && (!temp->isName() || !Token::Match(temp->next(), "[{:;]"))) continue; @@ -7529,7 +7531,7 @@ void Tokenizer::simplifyEnum() Token *typeTokenEnd = nullptr; // check for C++11 enum class - bool enumClass = isCPP() && Token::Match(tok->next(), "class|struct"); + const bool enumClass = isCPP() && Token::Match(tok->next(), "class|struct"); if (enumClass) tok->deleteNext(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 4542bbff5..86768d4f9 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -88,6 +88,8 @@ private: TEST_CASE(garbageCode47); // #6706 TEST_CASE(garbageCode48); // #6712 TEST_CASE(garbageCode49); // #6715 + TEST_CASE(garbageCode50); // #6718 + TEST_CASE(garbageCode51); // #6719 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -505,6 +507,14 @@ private: ASSERT_THROW(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }"), InternalError); } + void garbageCode50() { // #6718 + checkCode(" enum struct"); + } + + void garbageCode51() { // #6719 + checkCode(" (const \"C\" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = }"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"