Cppcheck
Classes | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
CheckClass Class Reference

Check classes. More...

#include <checkclass.h>

Inheritance diagram for CheckClass:
Check

Classes

struct  Usage
 Information about a member variable. More...
 

Public Member Functions

 CheckClass ()
 This constructor is used when registering the CheckClass. More...
 
- Public Member Functions inherited from Check
 Check (const std::string &aname)
 This constructor is used when registering the CheckClass. More...
 
virtual ~Check ()
 
 Check (const Check &)=delete
 
Checkoperator= (const Check &)=delete
 
const std::string & name () const
 class name, used to generate documentation More...
 

Static Public Attributes

static const std::set< std::string > stl_containers_not_const = { "map", "unordered_map", "std :: map|unordered_map <" }
 Set of the STL types whose operator[] is not const. More...
 

Private Types

enum class  Bool { TRUE , FALSE , BAILOUT }
 
enum class  MemberAccess { NONE , SELF , MEMBER }
 

Private Member Functions

 CheckClass (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks. More...
 
void runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
 Run checks on the normal token list. More...
 
void constructors ()
 Check that all class constructors are ok More...
 
void checkExplicitConstructors ()
 Check that constructors with single parameter are explicit, if they has to be. More...
 
void privateFunctions ()
 Check that all private functions are called More...
 
void checkMemset ()
 Check that the memsets are valid. More...
 
void checkMemsetType (const Scope *start, const Token *tok, const Scope *type, bool allocation, std::set< const Scope * > parsedTypes)
 
void operatorEqRetRefThis ()
 'operator=' should return reference to *this More...
 
void operatorEqToSelf ()
 'operator=' should check for assignment to self More...
 
void virtualDestructor ()
 The destructor in a base class should be virtual. More...
 
void thisSubtraction ()
 warn for "this-x". More...
 
void checkConst ()
 can member function be const? More...
 
void initializerListOrder ()
 Check initializer list order. More...
 
void initializationListUsage ()
 Suggest using initialization list. More...
 
void checkSelfInitialization ()
 Check for initialization of a member with itself. More...
 
void copyconstructors ()
 
void checkVirtualFunctionCallInConstructor ()
 call of virtual function in constructor/destructor More...
 
void checkDuplInheritedMembers ()
 Check duplicated inherited members. More...
 
void checkCopyCtorAndEqOperator ()
 Check that copy constructor and operator defined together. More...
 
void checkOverride ()
 Check that the override keyword is used when overriding virtual functions. More...
 
void checkUselessOverride ()
 Check that the overriden function is not identical to the base function. More...
 
void checkReturnByReference ()
 Check that large members are returned by reference from getter function. More...
 
void checkThisUseAfterFree ()
 When "self pointer" is destroyed, 'this' might become invalid. More...
 
void checkUnsafeClassRefMember ()
 Unsafe class check - const reference member. More...
 
Check::FileInfogetFileInfo (const Tokenizer &tokenizer, const Settings &settings) const override
 Parse current TU and extract file info. More...
 
Check::FileInfoloadFileInfoFromXml (const tinyxml2::XMLElement *xmlElement) const override
 
bool analyseWholeProgram (const CTU::FileInfo *ctu, const std::list< Check::FileInfo * > &fileInfo, const Settings &settings, ErrorLogger &errorLogger) override
 Analyse all file infos for all TU. More...
 
void noConstructorError (const Token *tok, const std::string &classname, bool isStruct)
 
void noExplicitConstructorError (const Token *tok, const std::string &classname, bool isStruct)
 
void copyConstructorShallowCopyError (const Token *tok, const std::string &varname)
 
void noCopyConstructorError (const Scope *scope, bool isdefault, const Token *alloc, bool inconclusive)
 
void noOperatorEqError (const Scope *scope, bool isdefault, const Token *alloc, bool inconclusive)
 
void noDestructorError (const Scope *scope, bool isdefault, const Token *alloc)
 
void uninitVarError (const Token *tok, bool isprivate, Function::Type functionType, const std::string &classname, const std::string &varname, bool derived, bool inconclusive)
 
void uninitVarError (const Token *tok, const std::string &classname, const std::string &varname)
 
void missingMemberCopyError (const Token *tok, Function::Type functionType, const std::string &classname, const std::string &varname)
 
void operatorEqVarError (const Token *tok, const std::string &classname, const std::string &varname, bool inconclusive)
 
void unusedPrivateFunctionError (const Token *tok, const std::string &classname, const std::string &funcname)
 
void memsetError (const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type, bool isContainer=false)
 
void memsetErrorReference (const Token *tok, const std::string &memfunc, const std::string &type)
 
void memsetErrorFloat (const Token *tok, const std::string &type)
 
void mallocOnClassError (const Token *tok, const std::string &memfunc, const Token *classTok, const std::string &classname)
 
void mallocOnClassWarning (const Token *tok, const std::string &memfunc, const Token *classTok)
 
void virtualDestructorError (const Token *tok, const std::string &Base, const std::string &Derived, bool inconclusive)
 
void thisSubtractionError (const Token *tok)
 
void operatorEqRetRefThisError (const Token *tok)
 
void operatorEqShouldBeLeftUnimplementedError (const Token *tok)
 
void operatorEqMissingReturnStatementError (const Token *tok, bool error)
 
void operatorEqToSelfError (const Token *tok)
 
void checkConstError (const Token *tok, const std::string &classname, const std::string &funcname, bool suggestStatic)
 
void checkConstError2 (const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic)
 
void initializerListError (const Token *tok1, const Token *tok2, const std::string &classname, const std::string &varname, const std::string &argname={})
 
void suggestInitializationList (const Token *tok, const std::string &varname)
 
void selfInitializationError (const Token *tok, const std::string &varname)
 
void pureVirtualFunctionCallInConstructorError (const Function *scopeFunction, const std::list< const Token * > &tokStack, const std::string &purefuncname)
 
void virtualFunctionCallInConstructorError (const Function *scopeFunction, const std::list< const Token * > &tokStack, const std::string &funcname)
 
void duplInheritedMembersError (const Token *tok1, const Token *tok2, const std::string &derivedName, const std::string &baseName, const std::string &memberName, bool derivedIsStruct, bool baseIsStruct, bool isFunction=false)
 
void copyCtorAndEqOperatorError (const Token *tok, const std::string &classname, bool isStruct, bool hasCopyCtor)
 
void overrideError (const Function *funcInBase, const Function *funcInDerived)
 
void uselessOverrideError (const Function *funcInBase, const Function *funcInDerived, bool isSameCode=false)
 
void returnByReferenceError (const Function *func, const Variable *var)
 
void thisUseAfterFree (const Token *self, const Token *free, const Token *use)
 
void unsafeClassRefMemberError (const Token *tok, const std::string &varname)
 
void checkDuplInheritedMembersRecursive (const Type *typeCurrent, const Type *typeBase)
 
void getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const override
 get error messages More...
 
std::string classInfo () const override
 get information about this class, used to generate documentation More...
 
void checkReturnPtrThis (const Scope *scope, const Function *func, const Token *tok, const Token *last)
 
void checkReturnPtrThis (const Scope *scope, const Function *func, const Token *tok, const Token *last, std::set< const Function * > &analyzedFunctions)
 
bool hasAllocation (const Function *func, const Scope *scope) const
 
bool hasAllocation (const Function *func, const Scope *scope, const Token *start, const Token *end) const
 
bool hasAllocationInIfScope (const Function *func, const Scope *scope, const Token *ifStatementScopeStart) const
 
bool isMemberVar (const Scope *scope, const Token *tok) const
 
bool checkConstFunc (const Scope *scope, const Function *func, MemberAccess &memberAccessed) const
 
void initializeVarList (const Function &func, std::list< const Function * > &callstack, const Scope *scope, std::vector< Usage > &usage) const
 parse a scope for a constructor or member function and set the "init" flags in the provided varlist More...
 
const std::list< const Token * > & getVirtualFunctionCalls (const Function &function, std::map< const Function *, std::list< const Token * >> &virtualFunctionCallsMap)
 gives a list of tokens where virtual functions are called directly or indirectly More...
 
bool checkThisUseAfterFreeRecursive (const Scope *classScope, const Function *func, const Variable *selfPointer, std::set< const Function * > callstack, const Token *&freeToken)
 Helper for checkThisUseAfterFree. More...
 

Static Private Member Functions

static std::string myName ()
 
static bool hasAssignSelf (const Function *func, const Token *rhs, const Token *&out_ifStatementScopeStart)
 
static Bool isInverted (const Token *tok, const Token *rhs)
 
static const TokengetIfStmtBodyStart (const Token *tok, const Token *rhs)
 
static bool isMemberFunc (const Scope *scope, const Token *tok)
 
static bool isConstMemberFunc (const Scope *scope, const Token *tok)
 
static bool isBaseClassMutableMemberFunc (const Token *tok, const Scope *scope)
 
static std::vector< UsagecreateUsageList (const Scope *scope)
 Create usage list that contains all scope members and also members of base classes without constructors. More...
 
static void assignVar (std::vector< Usage > &usageList, nonneg int varid)
 assign a variable in the varlist More...
 
static void assignVar (std::vector< Usage > &usageList, const Token *vartok)
 assign a variable in the varlist More...
 
static void initVar (std::vector< Usage > &usageList, nonneg int varid)
 initialize a variable in the varlist More...
 
static void assignAllVar (std::vector< Usage > &usageList)
 set all variables in list assigned More...
 
static void assignAllVarsVisibleFromScope (std::vector< Usage > &usageList, const Scope *scope)
 set all variable in list assigned, if visible from given scope More...
 
static void clearAllVar (std::vector< Usage > &usageList)
 set all variables in list not assigned and not initialized More...
 
static void getFirstVirtualFunctionCallStack (std::map< const Function *, std::list< const Token * >> &virtualFunctionCallsMap, const Token *callToken, std::list< const Token * > &pureFuncStack)
 looks for the first virtual function call stack More...
 
static bool canNotCopy (const Scope *scope)
 
static bool canNotMove (const Scope *scope)
 

Private Attributes

const SymbolDatabasemSymbolDatabase {}
 

Friends

class TestClass
 
class TestConstructors
 
class TestUnusedPrivateFunction
 

Additional Inherited Members

- Static Public Member Functions inherited from Check
static std::list< Check * > & instances ()
 List of registered check classes. More...
 
static void writeToErrorList (const ErrorMessage &errmsg)
 Write given error to stdout in xml format. More...
 
- Protected Member Functions inherited from Check
 Check (std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks. More...
 
void reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg)
 report an error More...
 
void reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
 report an error More...
 
void reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg)
 report an error More...
 
void reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
 report an error More...
 
void reportError (const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
 
void logChecker (const char id[])
 log checker More...
 
ErrorPath getErrorPath (const Token *errtok, const ValueFlow::Value *value, std::string bug) const
 
bool wrongData (const Token *tok, const char *str)
 Use WRONG_DATA in checkers when you check for wrong data. More...
 
- Static Protected Member Functions inherited from Check
static std::string getMessageId (const ValueFlow::Value &value, const char id[])
 
- Protected Attributes inherited from Check
const Tokenizer *const mTokenizer {}
 
const Settings *const mSettings {}
 
ErrorLogger *const mErrorLogger {}
 

Detailed Description

Check classes.

Uninitialized member variables, non-conforming operators, missing virtual destructor, etc

Definition at line 52 of file checkclass.h.

Member Enumeration Documentation

◆ Bool

enum CheckClass::Bool
strongprivate
Enumerator
TRUE 
FALSE 
BAILOUT 

Definition at line 302 of file checkclass.h.

◆ MemberAccess

enum CheckClass::MemberAccess
strongprivate
Enumerator
NONE 
SELF 
MEMBER 

Definition at line 310 of file checkclass.h.

Constructor & Destructor Documentation

◆ CheckClass() [1/2]

CheckClass::CheckClass ( )
inline

This constructor is used when registering the CheckClass.

Definition at line 59 of file checkclass.h.

◆ CheckClass() [2/2]

CheckClass::CheckClass ( const Tokenizer tokenizer,
const Settings settings,
ErrorLogger errorLogger 
)
private

This constructor is used when running checks.

Definition at line 119 of file checkclass.cpp.

Member Function Documentation

◆ analyseWholeProgram()

bool CheckClass::analyseWholeProgram ( const CTU::FileInfo ctu,
const std::list< Check::FileInfo * > &  fileInfo,
const Settings settings,
ErrorLogger errorLogger 
)
overrideprivatevirtual

Analyse all file infos for all TU.

Reimplemented from Check.

Definition at line 3640 of file checkclass.cpp.

References CWE_ONE_DEFINITION_RULE, emptyString, error, Check::logChecker(), normal, and ErrorLogger::reportErr().

◆ assignAllVar()

void CheckClass::assignAllVar ( std::vector< Usage > &  usageList)
staticprivate

set all variables in list assigned

Parameters
usageListreference to usage vector

Definition at line 694 of file checkclass.cpp.

Referenced by initializeVarList().

◆ assignAllVarsVisibleFromScope()

void CheckClass::assignAllVarsVisibleFromScope ( std::vector< Usage > &  usageList,
const Scope scope 
)
staticprivate

set all variable in list assigned, if visible from given scope

Parameters
usageListreference to usage vector
scopescope from which usages must be visible

Definition at line 700 of file checkclass.cpp.

References Type::classScope, Scope::definedType, Type::derivedFrom, and Type::BaseInfo::type.

Referenced by initializeVarList().

◆ assignVar() [1/2]

void CheckClass::assignVar ( std::vector< Usage > &  usageList,
const Token vartok 
)
staticprivate

assign a variable in the varlist

Parameters
usageListreference to usage vector
vartokvariable token

Definition at line 671 of file checkclass.cpp.

References assignVar(), and Token::varId().

◆ assignVar() [2/2]

void CheckClass::assignVar ( std::vector< Usage > &  usageList,
nonneg int  varid 
)
staticprivate

assign a variable in the varlist

Parameters
usageListreference to usage vector
varidid of variable to mark assigned

Definition at line 662 of file checkclass.cpp.

Referenced by assignVar(), checkConstFunc(), and initializeVarList().

◆ canNotCopy()

bool CheckClass::canNotCopy ( const Scope scope)
staticprivate

◆ canNotMove()

bool CheckClass::canNotMove ( const Scope scope)
staticprivate

◆ checkConst()

void CheckClass::checkConst ( )
private

◆ checkConstError()

void CheckClass::checkConstError ( const Token tok,
const std::string &  classname,
const std::string &  funcname,
bool  suggestStatic 
)
private

Definition at line 2602 of file checkclass.cpp.

References checkConstError2().

Referenced by checkConst(), and getErrorMessages().

◆ checkConstError2()

void CheckClass::checkConstError2 ( const Token tok1,
const Token tok2,
const std::string &  classname,
const std::string &  funcname,
bool  suggestStatic 
)
private

Definition at line 2607 of file checkclass.cpp.

References CWE398, inconclusive, performance, Check::reportError(), and style.

Referenced by checkConst(), and checkConstError().

◆ checkConstFunc()

bool CheckClass::checkConstFunc ( const Scope scope,
const Function func,
MemberAccess memberAccessed 
) const
private

◆ checkCopyCtorAndEqOperator()

void CheckClass::checkCopyCtorAndEqOperator ( )
private

◆ checkDuplInheritedMembers()

void CheckClass::checkDuplInheritedMembers ( )
private

◆ checkDuplInheritedMembersRecursive()

void CheckClass::checkDuplInheritedMembersRecursive ( const Type typeCurrent,
const Type typeBase 
)
private

◆ checkExplicitConstructors()

void CheckClass::checkExplicitConstructors ( )
private

◆ checkMemset()

void CheckClass::checkMemset ( )
private

◆ checkMemsetType()

void CheckClass::checkMemsetType ( const Scope start,
const Token tok,
const Scope type,
bool  allocation,
std::set< const Scope * >  parsedTypes 
)
private

◆ checkOverride()

void CheckClass::checkOverride ( )
private

◆ checkReturnByReference()

void CheckClass::checkReturnByReference ( )
private

◆ checkReturnPtrThis() [1/2]

void CheckClass::checkReturnPtrThis ( const Scope scope,
const Function func,
const Token tok,
const Token last 
)
private

Definition at line 1590 of file checkclass.cpp.

Referenced by checkReturnPtrThis(), and operatorEqRetRefThis().

◆ checkReturnPtrThis() [2/2]

void CheckClass::checkReturnPtrThis ( const Scope scope,
const Function func,
const Token tok,
const Token last,
std::set< const Function * > &  analyzedFunctions 
)
private

◆ checkSelfInitialization()

void CheckClass::checkSelfInitialization ( )
private

◆ checkThisUseAfterFree()

void CheckClass::checkThisUseAfterFree ( )
private

◆ checkThisUseAfterFreeRecursive()

bool CheckClass::checkThisUseAfterFreeRecursive ( const Scope classScope,
const Function func,
const Variable selfPointer,
std::set< const Function * >  callstack,
const Token *&  freeToken 
)
private

◆ checkUnsafeClassRefMember()

void CheckClass::checkUnsafeClassRefMember ( )
private

◆ checkUselessOverride()

void CheckClass::checkUselessOverride ( )
private

◆ checkVirtualFunctionCallInConstructor()

void CheckClass::checkVirtualFunctionCallInConstructor ( )
private

◆ classInfo()

std::string CheckClass::classInfo ( ) const
inlineoverrideprivatevirtual

get information about this class, used to generate documentation

Implements Check.

Definition at line 267 of file checkclass.h.

◆ clearAllVar()

void CheckClass::clearAllVar ( std::vector< Usage > &  usageList)
staticprivate

set all variables in list not assigned and not initialized

Parameters
usageListreference to usage vector

Definition at line 716 of file checkclass.cpp.

Referenced by constructors().

◆ constructors()

void CheckClass::constructors ( )
private

Check that all class constructors are ok

Definition at line 128 of file checkclass.cpp.

References Function::access, Function::arg, Function::argCount(), bailout, Scope::bodyStart, canNotCopy(), canNotMove(), Settings::certainty, SymbolDatabase::classAndStructScopes, Scope::classDef, Scope::className, clearAllVar(), Function::constructorMemberInitialization(), ValueType::containerTypeToken, Standards::cpp, Standards::CPP11, createUsageList(), Scope::definedType, Type::derivedFrom, Function::eConstructor, Function::eCopyConstructor, Function::eMoveConstructor, Token::eName, Function::eOperatorEqual, Scope::eUnion, Type::False, Scope::functionList, Function::functionScope, Library::getTypeCheck(), Variable::getTypeName(), Function::hasBody(), Variable::hasDefault(), Settings::hasLib(), inconclusive, initializeVarList(), Variable::isClass(), Variable::isConst(), Function::isConstructor(), Function::isDefault(), SimpleEnableGroup< T >::isEnabled(), Variable::isInit(), Function::isOperator(), Variable::isPointer(), Variable::isPointerArray(), Settings::isPremiumEnabled(), Variable::isPrivate(), Token::isStandardType(), Variable::isStatic(), Variable::isStlType(), isVariableCopyNeeded(), isVclTypeInit(), Settings::library, Token::link(), Check::logChecker(), Token::Match(), missingMemberCopyError(), Check::mSettings, mSymbolDatabase, Variable::name(), Variable::nameToken(), Type::needInitialization, Function::nestedIn, Scope::nestedIn, Scope::nestedList, Token::next(), noConstructorError(), Scope::numConstructors, Scope::numCopyOrMoveConstructors, operatorEqVarError(), Library::podtype(), ValueType::pointer, precedes(), Token::previous(), Private, Variable::scope(), Token::scope(), SymbolDatabase::scopeList, Settings::severity, Token::simpleMatch(), Settings::standards, Token::str(), style, Library::suppress, Function::token, Function::tokenDef, Token::tokType(), Type::True, Variable::type(), Function::type, Scope::type, Token::type(), Variable::typeScope(), uninitVarError(), Variable::valueType(), Scope::varlist, and warning.

Referenced by runChecks().

◆ copyconstructors()

void CheckClass::copyconstructors ( )
private

◆ copyConstructorShallowCopyError()

void CheckClass::copyConstructorShallowCopyError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 540 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and warning.

Referenced by copyconstructors(), and getErrorMessages().

◆ copyCtorAndEqOperatorError()

void CheckClass::copyCtorAndEqOperatorError ( const Token tok,
const std::string &  classname,
bool  isStruct,
bool  hasCopyCtor 
)
private

◆ createUsageList()

std::vector< CheckClass::Usage > CheckClass::createUsageList ( const Scope scope)
staticprivate

Create usage list that contains all scope members and also members of base classes without constructors.

Parameters
scopecurrent class scope

Definition at line 650 of file checkclass.cpp.

References getAllVariableMembers().

Referenced by constructors().

◆ duplInheritedMembersError()

void CheckClass::duplInheritedMembersError ( const Token tok1,
const Token tok2,
const std::string &  derivedName,
const std::string &  baseName,
const std::string &  memberName,
bool  derivedIsStruct,
bool  baseIsStruct,
bool  isFunction = false 
)
private

Definition at line 3058 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and warning.

Referenced by checkDuplInheritedMembersRecursive(), and getErrorMessages().

◆ getErrorMessages()

void CheckClass::getErrorMessages ( ErrorLogger errorLogger,
const Settings settings 
) const
inlineoverrideprivatevirtual

◆ getFileInfo()

Check::FileInfo * CheckClass::getFileInfo ( const Tokenizer tokenizer,
const Settings settings 
) const
overrideprivatevirtual

◆ getFirstVirtualFunctionCallStack()

void CheckClass::getFirstVirtualFunctionCallStack ( std::map< const Function *, std::list< const Token * >> &  virtualFunctionCallsMap,
const Token callToken,
std::list< const Token * > &  pureFuncStack 
)
staticprivate

looks for the first virtual function call stack

Parameters
virtualFunctionCallsMapmap of results obtained from getVirtualFunctionCalls
callTokentoken where pure virtual function is called directly or indirectly
[in,out]pureFuncStacklist to append the stack

Definition at line 2871 of file checkclass.cpp.

References Token::function(), Function::hasBody(), Function::isImplicitlyVirtual(), Function::isPure(), and Function::tokenDef.

Referenced by checkVirtualFunctionCallInConstructor().

◆ getIfStmtBodyStart()

const Token * CheckClass::getIfStmtBodyStart ( const Token tok,
const Token rhs 
)
staticprivate

◆ getVirtualFunctionCalls()

const std::list< const Token * > & CheckClass::getVirtualFunctionCalls ( const Function function,
std::map< const Function *, std::list< const Token * >> &  virtualFunctionCallsMap 
)
private

gives a list of tokens where virtual functions are called directly or indirectly

Parameters
functionfunction to be checked
virtualFunctionCallsMapmap of results for already checked functions
Returns
list of tokens where pure virtual functions are called

Definition at line 2813 of file checkclass.cpp.

References Function::eConstructor, Function::eCopyConstructor, Function::eDestructor, Scope::eLambda, Function::eMoveConstructor, Library::ignorefunction(), Function::isImplicitlyVirtual(), Function::isPure(), Settings::library, Token::link(), Token::Match(), Check::mSettings, Function::nestedIn, Token::previous(), Token::simpleMatch(), and Token::str().

Referenced by checkVirtualFunctionCallInConstructor().

◆ hasAllocation() [1/2]

bool CheckClass::hasAllocation ( const Function func,
const Scope scope 
) const
private

◆ hasAllocation() [2/2]

bool CheckClass::hasAllocation ( const Function func,
const Scope scope,
const Token start,
const Token end 
) const
private

◆ hasAllocationInIfScope()

bool CheckClass::hasAllocationInIfScope ( const Function func,
const Scope scope,
const Token ifStatementScopeStart 
) const
private

◆ hasAssignSelf()

bool CheckClass::hasAssignSelf ( const Function func,
const Token rhs,
const Token *&  out_ifStatementScopeStart 
)
staticprivate

◆ initializationListUsage()

void CheckClass::initializationListUsage ( )
private

◆ initializerListError()

void CheckClass::initializerListError ( const Token tok1,
const Token tok2,
const std::string &  classname,
const std::string &  varname,
const std::string &  argname = {} 
)
private

Definition at line 2723 of file checkclass.cpp.

References CWE398, inconclusive, Check::reportError(), and style.

Referenced by getErrorMessages(), and initializerListOrder().

◆ initializerListOrder()

void CheckClass::initializerListOrder ( )
private

◆ initializeVarList()

void CheckClass::initializeVarList ( const Function func,
std::list< const Function * > &  callstack,
const Scope scope,
std::vector< Usage > &  usage 
) const
private

parse a scope for a constructor or member function and set the "init" flags in the provided varlist

Parameters
funcreference to the function that should be checked
callstackthe function doesn't look into recursive function calls.
scopepointer to variable Scope
usagereference to usage vector
Todo:
false negative: just bail
Todo:
false negative: we assume function changes variable state
Todo:
false negative: just bail
Todo:
False Negative: we should look at the base class functions to see if they call any derived class virtual functions that change the derived class state

Definition at line 751 of file checkclass.cpp.

References Function::arg, assignAllVar(), assignAllVarsVisibleFromScope(), assignVar(), astIsRangeBasedForDecl(), Token::astParent(), bailout, Scope::bodyEnd, Type::classScope, Scope::definedType, Function::eOperatorEqual, Type::friendList, Token::function(), Function::functionScope, Function::hasBody(), initVar(), isBaseClassMutableMemberFunc(), Function::isConst(), Function::isConstructor(), isLikelyStreamRead(), Function::isStatic(), isVariableChangedByFunctionCall(), Token::link(), Token::linkAt(), Token::Match(), Check::mSettings, Function::name(), Function::nestedIn, Token::next(), ValueType::pointer, Token::previous(), Token::simpleMatch(), Token::str(), Token::strAt(), Token::tokAt(), Function::tokenDef, Function::type, Token::valueType(), Token::variable(), Token::varId(), and Scope::varlist.

Referenced by constructors().

◆ initVar()

void CheckClass::initVar ( std::vector< Usage > &  usageList,
nonneg int  varid 
)
staticprivate

initialize a variable in the varlist

Parameters
usageListreference to usage vector
varidid of variable to mark initialized

Definition at line 685 of file checkclass.cpp.

Referenced by initializeVarList().

◆ isBaseClassMutableMemberFunc()

bool CheckClass::isBaseClassMutableMemberFunc ( const Token tok,
const Scope scope 
)
staticprivate

◆ isConstMemberFunc()

bool CheckClass::isConstMemberFunc ( const Scope scope,
const Token tok 
)
staticprivate

◆ isInverted()

CheckClass::Bool CheckClass::isInverted ( const Token tok,
const Token rhs 
)
staticprivate

◆ isMemberFunc()

bool CheckClass::isMemberFunc ( const Scope scope,
const Token tok 
)
staticprivate

◆ isMemberVar()

bool CheckClass::isMemberVar ( const Scope scope,
const Token tok 
) const
private

◆ loadFileInfoFromXml()

Check::FileInfo * CheckClass::loadFileInfoFromXml ( const tinyxml2::XMLElement *  xmlElement) const
overrideprivatevirtual

Reimplemented from Check.

Definition at line 3612 of file checkclass.cpp.

References Check::name().

◆ mallocOnClassError()

void CheckClass::mallocOnClassError ( const Token tok,
const std::string &  memfunc,
const Token classTok,
const std::string &  classname 
)
private

Definition at line 1526 of file checkclass.cpp.

References CWE665, error, normal, and Check::reportError().

Referenced by checkMemsetType(), and getErrorMessages().

◆ mallocOnClassWarning()

void CheckClass::mallocOnClassWarning ( const Token tok,
const std::string &  memfunc,
const Token classTok 
)
private

Definition at line 1516 of file checkclass.cpp.

References CWE762, normal, Check::reportError(), and warning.

Referenced by checkMemset(), and getErrorMessages().

◆ memsetError()

void CheckClass::memsetError ( const Token tok,
const std::string &  memfunc,
const std::string &  classname,
const std::string &  type,
bool  isContainer = false 
)
private

Definition at line 1537 of file checkclass.cpp.

References CWE762, error, normal, and Check::reportError().

Referenced by checkMemset(), checkMemsetType(), and getErrorMessages().

◆ memsetErrorFloat()

void CheckClass::memsetErrorFloat ( const Token tok,
const std::string &  type 
)
private

Definition at line 1556 of file checkclass.cpp.

References CWE758, normal, portability, and Check::reportError().

Referenced by checkMemsetType(), and getErrorMessages().

◆ memsetErrorReference()

void CheckClass::memsetErrorReference ( const Token tok,
const std::string &  memfunc,
const std::string &  type 
)
private

Definition at line 1549 of file checkclass.cpp.

References CWE665, error, normal, and Check::reportError().

Referenced by checkMemsetType(), and getErrorMessages().

◆ missingMemberCopyError()

void CheckClass::missingMemberCopyError ( const Token tok,
Function::Type  functionType,
const std::string &  classname,
const std::string &  varname 
)
private

Definition at line 1117 of file checkclass.cpp.

References CWE398, inconclusive, Check::reportError(), and warning.

Referenced by constructors(), and getErrorMessages().

◆ myName()

static std::string CheckClass::myName ( )
inlinestaticprivate

Definition at line 263 of file checkclass.h.

◆ noConstructorError()

void CheckClass::noConstructorError ( const Token tok,
const std::string &  classname,
bool  isStruct 
)
private

Definition at line 1079 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by constructors(), and getErrorMessages().

◆ noCopyConstructorError()

void CheckClass::noCopyConstructorError ( const Scope scope,
bool  isdefault,
const Token alloc,
bool  inconclusive 
)
private

◆ noDestructorError()

void CheckClass::noDestructorError ( const Scope scope,
bool  isdefault,
const Token alloc 
)
private

Definition at line 576 of file checkclass.cpp.

References CWE398, noMemberErrorMessage(), normal, Check::reportError(), and warning.

Referenced by copyconstructors(), and getErrorMessages().

◆ noExplicitConstructorError()

void CheckClass::noExplicitConstructorError ( const Token tok,
const std::string &  classname,
bool  isStruct 
)
private

Definition at line 1087 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by checkExplicitConstructors(), and getErrorMessages().

◆ noOperatorEqError()

void CheckClass::noOperatorEqError ( const Scope scope,
bool  isdefault,
const Token alloc,
bool  inconclusive 
)
private

◆ operatorEqMissingReturnStatementError()

void CheckClass::operatorEqMissingReturnStatementError ( const Token tok,
bool  error 
)
private

◆ operatorEqRetRefThis()

void CheckClass::operatorEqRetRefThis ( )
private

◆ operatorEqRetRefThisError()

void CheckClass::operatorEqRetRefThisError ( const Token tok)
private

◆ operatorEqShouldBeLeftUnimplementedError()

void CheckClass::operatorEqShouldBeLeftUnimplementedError ( const Token tok)
private

Definition at line 1687 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by checkReturnPtrThis(), and getErrorMessages().

◆ operatorEqToSelf()

void CheckClass::operatorEqToSelf ( )
private

◆ operatorEqToSelfError()

void CheckClass::operatorEqToSelfError ( const Token tok)
private

Definition at line 1896 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and warning.

Referenced by getErrorMessages(), and operatorEqToSelf().

◆ operatorEqVarError()

void CheckClass::operatorEqVarError ( const Token tok,
const std::string &  classname,
const std::string &  varname,
bool  inconclusive 
)
private

Definition at line 1127 of file checkclass.cpp.

References CWE398, inconclusive, normal, Check::reportError(), and warning.

Referenced by constructors(), and getErrorMessages().

◆ overrideError()

void CheckClass::overrideError ( const Function funcInBase,
const Function funcInDerived 
)
private

◆ privateFunctions()

void CheckClass::privateFunctions ( )
private

◆ pureVirtualFunctionCallInConstructorError()

void CheckClass::pureVirtualFunctionCallInConstructorError ( const Function scopeFunction,
const std::list< const Token * > &  tokStack,
const std::string &  purefuncname 
)
private

◆ returnByReferenceError()

void CheckClass::returnByReferenceError ( const Function func,
const Variable var 
)
private

◆ runChecks()

void CheckClass::runChecks ( const Tokenizer tokenizer,
ErrorLogger errorLogger 
)
inlineoverrideprivatevirtual

◆ selfInitializationError()

void CheckClass::selfInitializationError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 2773 of file checkclass.cpp.

References CWE665, error, normal, and Check::reportError().

Referenced by checkSelfInitialization(), and getErrorMessages().

◆ suggestInitializationList()

void CheckClass::suggestInitializationList ( const Token tok,
const std::string &  varname 
)
private

Definition at line 1216 of file checkclass.cpp.

References CWE398, normal, performance, and Check::reportError().

Referenced by getErrorMessages(), and initializationListUsage().

◆ thisSubtraction()

void CheckClass::thisSubtraction ( )
private

◆ thisSubtractionError()

void CheckClass::thisSubtractionError ( const Token tok)
private

Definition at line 2084 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and warning.

Referenced by getErrorMessages(), and thisSubtraction().

◆ thisUseAfterFree()

void CheckClass::thisUseAfterFree ( const Token self,
const Token free,
const Token use 
)
private

◆ uninitVarError() [1/2]

void CheckClass::uninitVarError ( const Token tok,
bool  isprivate,
Function::Type  functionType,
const std::string &  classname,
const std::string &  varname,
bool  derived,
bool  inconclusive 
)
private

◆ uninitVarError() [2/2]

void CheckClass::uninitVarError ( const Token tok,
const std::string &  classname,
const std::string &  varname 
)
private

Definition at line 1109 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and warning.

◆ unsafeClassRefMemberError()

void CheckClass::unsafeClassRefMemberError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 3491 of file checkclass.cpp.

References CWE, normal, Check::reportError(), and warning.

Referenced by checkUnsafeClassRefMember(), and getErrorMessages().

◆ unusedPrivateFunctionError()

void CheckClass::unusedPrivateFunctionError ( const Token tok,
const std::string &  classname,
const std::string &  funcname 
)
private

Definition at line 1334 of file checkclass.cpp.

References CWE398, normal, Check::reportError(), and style.

Referenced by getErrorMessages(), and privateFunctions().

◆ uselessOverrideError()

void CheckClass::uselessOverrideError ( const Function funcInBase,
const Function funcInDerived,
bool  isSameCode = false 
)
private

◆ virtualDestructor()

void CheckClass::virtualDestructor ( )
private

◆ virtualDestructorError()

void CheckClass::virtualDestructorError ( const Token tok,
const std::string &  Base,
const std::string &  Derived,
bool  inconclusive 
)
private

◆ virtualFunctionCallInConstructorError()

void CheckClass::virtualFunctionCallInConstructorError ( const Function scopeFunction,
const std::list< const Token * > &  tokStack,
const std::string &  funcname 
)
private

Friends And Related Function Documentation

◆ TestClass

friend class TestClass
friend

Definition at line 53 of file checkclass.h.

◆ TestConstructors

friend class TestConstructors
friend

Definition at line 54 of file checkclass.h.

◆ TestUnusedPrivateFunction

friend class TestUnusedPrivateFunction
friend

Definition at line 55 of file checkclass.h.

Member Data Documentation

◆ mSymbolDatabase

const SymbolDatabase* CheckClass::mSymbolDatabase {}
private

◆ stl_containers_not_const

const std::set< std::string > CheckClass::stl_containers_not_const = { "map", "unordered_map", "std :: map|unordered_map <" }
static

Set of the STL types whose operator[] is not const.

Definition at line 62 of file checkclass.h.

Referenced by checkConstFunc(), and isWithoutSideEffects().


The documentation for this class was generated from the following files: