From 468a983db1356576214d854d8930dc9521fdc685 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 22 Mar 2011 21:24:28 -0400 Subject: [PATCH] use the symbol database to look up base classes in CheckClass::noMemset check --- lib/checkclass.cpp | 39 +++++++++++++-------------------------- lib/checkclass.h | 2 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 0a0f7a3bb..b631e4c0e 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -689,35 +689,19 @@ void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string // ClassCheck: Check that memset is not used on classes //--------------------------------------------------------------------------- -void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Token *typeTok) +void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Scope *type) { - // Warn if type is a class or struct that contains any std::* variables - const Scope *scope = symbolDatabase->findVariableType(start, typeTok); - if (!scope) - return; - - const Token *tstruct = scope->classDef; - const std::string &typeName = tstruct->str(); - - if (tstruct->tokAt(2)->str() == ":") + // recursively check all parent classes + for (size_t i = 0; i < type->derivedFrom.size(); i++) { - tstruct = tstruct->tokAt(3); - for (; tstruct; tstruct = tstruct->next()) - { - while (Token::Match(tstruct, "public|private|protected|virtual")) - { - tstruct = tstruct->next(); - } - - // recursively check all parent classes - checkMemsetType(start, tok, tstruct); - - tstruct = tstruct->next(); - if (tstruct->str() != ",") - break; - } + if (type->derivedFrom[i].scope) + checkMemsetType(start, tok, type->derivedFrom[i].scope); } + // Warn if type is a class or struct that contains any std::* variables + const Token *tstruct = type->classDef; + const std::string &typeName = tstruct->str(); + for (; tstruct; tstruct = tstruct->next()) { if (tstruct->str() == "}") @@ -823,7 +807,10 @@ void CheckClass::noMemset() if (!typeTok) continue; - checkMemsetType(&(*scope), tok, typeTok); + const Scope *type = symbolDatabase->findVariableType(&(*scope), typeTok); + + if (type) + checkMemsetType(&(*scope), tok, type); } } } diff --git a/lib/checkclass.h b/lib/checkclass.h index a07d02e63..25f2eddae 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -84,7 +84,7 @@ public: * Important: The checking doesn't work on simplified tokens list. */ void noMemset(); - void checkMemsetType(const Scope *start, const Token *tok, const Token *typeTok); + void checkMemsetType(const Scope *start, const Token *tok, const Scope *type); /** @brief 'operator=' should return something and it should not be const. */ void operatorEq();