| 2905 | //--------------------------------------------------------------------------- |
| 2906 | |
| 2907 | void 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 | |
| 2936 | void CheckClassImpl::selfInitializationError(const Token* tok, const std::string& varname) |
| 2937 | { |
no test coverage detected