Skip to content
3 changes: 2 additions & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ void CheckClass::assignAllVarsVisibleFromScope(std::vector<Usage>& 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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
Expand Down
8 changes: 8 additions & 0 deletions test/testconstructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,14 @@ class TestConstructors : public TestFixture {
"[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() {
Expand Down
3 changes: 3 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6759,6 +6759,9 @@ class TestTokenizer : public TestFixture {

// #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'");
}


Expand Down