diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 937c2874f..d7576ccd3 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -697,7 +697,8 @@ void CheckClass::assignAllVarsVisibleFromScope(std::vector& usageList, co for (const Type::BaseInfo& i : scope->definedType->derivedFrom) { const Type *derivedFrom = i.type; - assignAllVarsVisibleFromScope(usageList, derivedFrom->classScope); + if (derivedFrom) + assignAllVarsVisibleFromScope(usageList, derivedFrom->classScope); } } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 671b37f98..2d1102291 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7634,6 +7634,8 @@ void Tokenizer::findGarbageCode() const syntaxError(tok2, "Unexpected token '" + tok2->str() + "'"); } } + if (Token::Match(tok, "enum : %num%| {")) + syntaxError(tok->tokAt(2), "Unexpected token '" + tok->strAt(2) + "'"); } // Keywords in global scope diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index f0d69caff..a1d0ba0a6 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -656,7 +656,7 @@ static bool iscpp11init_impl(const Token * const tok) if (!Token::Match(colonTok->tokAt(-1), "%name%|%num% :")) return false; const Token* caseTok = colonTok->tokAt(-2); - while (Token::Match(caseTok->tokAt(-1), "::|%name%")) + while (caseTok && Token::Match(caseTok->tokAt(-1), "::|%name%")) caseTok = caseTok->tokAt(-1); return Token::simpleMatch(caseTok, "case"); }; diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index b6ec94996..e49a66ce2 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -1440,6 +1440,14 @@ private: "[test.cpp:9]: (warning) Member variable 'B::ca' is not assigned a value in 'B::operator='.\n", errout.str()); + check("class C : B {\n" + " virtual C& operator=(C& c);\n" + "};\n" + "class D : public C {\n" + " virtual C& operator=(C& c) { return C::operator=(c); };\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } void initvar_derived_pod_struct_with_union() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index dc0477197..4410197e8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6759,6 +6759,9 @@ private: // #9445 - typeof is not a keyword in C ASSERT_NO_THROW(tokenizeAndStringify("void foo() { char *typeof, *value; }", false, Settings::Native, "test.c")); + + ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : { };"), InternalError, "syntax error: Unexpected token '{'"); + ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'"); }