MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkSelfInitialization

Method checkSelfInitialization

lib/checkclass.cpp:2907–2934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2905//---------------------------------------------------------------------------
2906
2907void CheckClassImpl::checkSelfInitialization()
2908{
2909 logChecker("CheckClass::checkSelfInitialization");
2910
2911 for (const Scope *scope : mSymbolDatabase->functionScopes) {
2912 const Function* function = scope->function;
2913 if (!function || !function->isConstructor())
2914 continue;
2915
2916 const Token* tok = function->arg->link()->next();
2917 if (tok->str() != ":")
2918 continue;
2919
2920 for (; tok != scope->bodyStart; tok = tok->next()) {
2921 if (Token::Match(tok, "[:,] %var% (|{")) {
2922 const Token* varTok = tok->next();
2923 if (Token::Match(varTok->astParent(), "(|{")) {
2924 if (const Token* initTok = varTok->astParent()->astOperand2()) {
2925 if (initTok->varId() == varTok->varId())
2926 selfInitializationError(tok, varTok->str());
2927 else if (initTok->isCast() && ((initTok->astOperand1() && initTok->astOperand1()->varId() == varTok->varId()) || (initTok->astOperand2() && initTok->astOperand2()->varId() == varTok->varId())))
2928 selfInitializationError(tok, varTok->str());
2929 }
2930 }
2931 }
2932 }
2933 }
2934}
2935
2936void CheckClassImpl::selfInitializationError(const Token* tok, const std::string& varname)
2937{

Callers 1

runChecksMethod · 0.80

Calls 6

nextMethod · 0.80
astParentMethod · 0.80
astOperand2Method · 0.80
isCastMethod · 0.80
astOperand1Method · 0.80
strMethod · 0.45

Tested by

no test coverage detected