| 3384 | } |
| 3385 | |
| 3386 | void CheckOtherImpl::checkRedundantCopy() |
| 3387 | { |
| 3388 | if (!mSettings.severity.isEnabled(Severity::performance) || mTokenizer->isC() || !mSettings.certainty.isEnabled(Certainty::inconclusive)) |
| 3389 | return; |
| 3390 | |
| 3391 | logChecker("CheckOther::checkRedundantCopy"); // c++,performance,inconclusive |
| 3392 | |
| 3393 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 3394 | |
| 3395 | for (const Variable* var : symbolDatabase->variableList()) { |
| 3396 | if (!var || var->isReference() || var->isPointer() || |
| 3397 | (!var->type() && !var->isStlType() && !(var->valueType() && var->valueType()->container)) || // bailout if var is of standard type, if it is a pointer or non-const |
| 3398 | (!var->isConst() && isVariableChanged(var, mSettings))) |
| 3399 | continue; |
| 3400 | |
| 3401 | const Token* startTok = var->nameToken(); |
| 3402 | if (startTok->strAt(1) == "=") // %type% %name% = ... ; |
| 3403 | ; |
| 3404 | else if (Token::Match(startTok->next(), "(|{") && var->isClass()) { |
| 3405 | if (!var->typeScope() && !(var->valueType() && var->valueType()->container)) |
| 3406 | continue; |
| 3407 | // Object is instantiated. Warn if constructor takes arguments by value. |
| 3408 | if (var->typeScope() && constructorTakesReference(var->typeScope())) |
| 3409 | continue; |
| 3410 | } else if (Token::simpleMatch(startTok->next(), ";") && startTok->next()->isSplittedVarDeclEq()) { |
| 3411 | startTok = startTok->tokAt(2); |
| 3412 | } else |
| 3413 | continue; |
| 3414 | |
| 3415 | const Token* tok = startTok->next()->astOperand2(); |
| 3416 | if (!tok) |
| 3417 | continue; |
| 3418 | if (!checkFunctionReturnsRef(tok, mSettings) && !checkVariableAssignment(tok, var->valueType(), mSettings)) |
| 3419 | continue; |
| 3420 | redundantCopyError(startTok, startTok->str()); |
| 3421 | } |
| 3422 | } |
| 3423 | |
| 3424 | void CheckOtherImpl::redundantCopyError(const Token *tok,const std::string& varname) |
| 3425 | { |
no test coverage detected