From a2ecf173611e32908d371f64dabd0d471e1eb5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 5 Feb 2024 20:21:53 +0100 Subject: [PATCH] fixed many `COPY_INSTEAD_OF_MOVE` Coverity warnings (#5944) --- cli/cppcheckexecutor.cpp | 2 +- cli/processexecutor.cpp | 2 +- lib/astutils.cpp | 2 +- lib/checkautovariables.cpp | 2 +- lib/checkautovariables.h | 9 +++--- lib/checkclass.cpp | 4 +-- lib/checkcondition.cpp | 11 +++---- lib/checkcondition.h | 12 ++++---- lib/checkother.cpp | 4 +-- lib/checkother.h | 10 +++---- lib/checkstl.cpp | 10 +++---- lib/checkstl.h | 5 ++-- lib/checkuninitvar.h | 3 +- lib/checkunusedfunctions.cpp | 2 +- lib/clangimport.cpp | 8 ++--- lib/cppcheck.cpp | 12 ++++---- lib/errorlogger.cpp | 2 +- lib/importproject.cpp | 4 +-- lib/library.cpp | 4 +-- lib/pathanalysis.cpp | 2 +- lib/preprocessor.cpp | 6 ++-- lib/programmemory.cpp | 2 +- lib/suppressions.cpp | 2 +- lib/symboldatabase.cpp | 4 +-- lib/templatesimplifier.cpp | 4 +-- lib/token.cpp | 4 +-- lib/tokenize.cpp | 8 ++--- lib/valueflow.cpp | 58 ++++++++++++++++++------------------ 28 files changed, 96 insertions(+), 102 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index d2e3d90944d..3ce9d95944f 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -194,7 +194,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[]) mStdLogger = new StdLogger(settings); CppCheck cppCheck(*mStdLogger, true, executeCommand); - cppCheck.settings() = settings; + cppCheck.settings() = settings; // this is a copy const int ret = check_wrapper(cppCheck); diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 9a514c66c67..cd016559ad2 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -392,7 +392,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const { std::list locations; locations.emplace_back(childname, 0, 0); - const ErrorMessage errmsg(locations, + const ErrorMessage errmsg(std::move(locations), emptyString, Severity::error, "Internal error: " + msg, diff --git a/lib/astutils.cpp b/lib/astutils.cpp index c8eebebb0f3..8faf3bceff4 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3255,7 +3255,7 @@ bool isConstVarExpression(const Token *tok, std::function sk if (Token::Match(tok, "%cop%|[|.")) { if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1(), skipPredicate)) return false; - if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), skipPredicate)) + if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), std::move(skipPredicate))) return false; return true; } diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index b7f5626d96c..b205721d748 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -575,7 +575,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token ErrorPath errorPath; const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath); if (var && isInScope(var->nameToken(), tok->scope())) { - errorDanglingReference(tok, var, errorPath); + errorDanglingReference(tok, var, std::move(errorPath)); continue; } // Reference to temporary diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 47cbdbcf818..de714d2f304 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -91,13 +91,12 @@ class CPPCHECKLIB CheckAutoVariables : public Check { void errorUselessAssignmentPtrArg(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override { - ErrorPath errorPath; CheckAutoVariables c(nullptr,settings,errorLogger); c.errorAutoVariableAssignment(nullptr, false); - c.errorReturnReference(nullptr, errorPath, false); - c.errorDanglingReference(nullptr, nullptr, errorPath); - c.errorReturnTempReference(nullptr, errorPath, false); - c.errorDanglingTempReference(nullptr, errorPath, false); + c.errorReturnReference(nullptr, ErrorPath{}, false); + c.errorDanglingReference(nullptr, nullptr, ErrorPath{}); + c.errorReturnTempReference(nullptr, ErrorPath{}, false); + c.errorDanglingTempReference(nullptr, ErrorPath{}, false); c.errorInvalidDeallocation(nullptr, nullptr); c.errorUselessAssignmentArg(nullptr); c.errorUselessAssignmentPtrArg(nullptr); diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 666c18dfbb6..5bed9fb51c8 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3343,7 +3343,7 @@ void CheckClass::checkThisUseAfterFree() const Token * freeToken = nullptr; std::set callstack; - checkThisUseAfterFreeRecursive(classScope, &func, &var, callstack, &freeToken); + checkThisUseAfterFreeRecursive(classScope, &func, &var, std::move(callstack), &freeToken); } } } @@ -3517,7 +3517,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti continue; MyFileInfo::NameLoc nameLoc; - nameLoc.className = name; + nameLoc.className = std::move(name); nameLoc.fileName = tokenizer->list.file(classScope->classDef); nameLoc.lineNumber = classScope->classDef->linenr(); nameLoc.column = classScope->classDef->column(); diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 0e3fe825a21..2da672083de 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -505,7 +505,7 @@ void CheckCondition::duplicateCondition() ErrorPath errorPath; if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, mSettings, mTokenizer->isCPP()) && isSameExpression(mTokenizer->isCPP(), true, cond1, cond2, mSettings->library, true, true, &errorPath)) - duplicateConditionError(cond1, cond2, errorPath); + duplicateConditionError(cond1, cond2, std::move(errorPath)); } } @@ -558,7 +558,7 @@ void CheckCondition::multiCondition() else if (isOppositeCond( true, mTokenizer->isCPP(), cond1, tok2->astOperand2(), mSettings->library, true, true, &errorPath) && !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings, mTokenizer->isCPP())) - oppositeElseIfConditionError(cond1, tok2->astOperand2(), errorPath); + oppositeElseIfConditionError(cond1, tok2->astOperand2(), std::move(errorPath)); } } } @@ -1193,7 +1193,7 @@ void CheckCondition::checkIncorrectLogicOperator() } const std::string cond1 = expr1 + " " + tok->str() + " (" + expr2 + " " + tok->astOperand2()->str() + " " + expr3 + ")"; - const std::string cond2 = expr1; + const std::string cond2 = std::move(expr1); const std::string cond1VerboseMsg = expr1VerboseMsg + " " + tok->str() + " " + expr2VerboseMsg + " " + tok->astOperand2()->str() + " " + expr3VerboseMsg; const std::string& cond2VerboseMsg = expr1VerboseMsg; @@ -1316,9 +1316,10 @@ void CheckCondition::checkIncorrectLogicOperator() const std::string cond2str = conditionString(not2, expr2, op2, value2); if (printWarning && (alwaysTrue || alwaysFalse)) { const std::string text = cond1str + " " + tok->str() + " " + cond2str; - incorrectLogicOperatorError(tok, text, alwaysTrue, inconclusive, errorPath); + incorrectLogicOperatorError(tok, text, alwaysTrue, inconclusive, std::move(errorPath)); } else if (printStyle && (firstTrue || secondTrue)) { - const int which = isfloat ? sufficientCondition(op1, not1, d1, op2, not2, d2, isAnd) : sufficientCondition(op1, not1, i1, op2, not2, i2, isAnd); + // cppcheck-suppress accessMoved - TODO: FP - see #12174 + const int which = isfloat ? sufficientCondition(std::move(op1), not1, d1, std::move(op2), not2, d2, isAnd) : sufficientCondition(std::move(op1), not1, i1, std::move(op2), not2, i2, isAnd); std::string text; if (which != 0) { text = "The condition '" + (which == 1 ? cond2str : cond1str) + "' is redundant since '" + (which == 1 ? cond1str : cond2str) + "' is sufficient."; diff --git a/lib/checkcondition.h b/lib/checkcondition.h index 18d30ecb236..f7f127a3184 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -175,18 +175,16 @@ class CPPCHECKLIB CheckCondition : public Check { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override { CheckCondition c(nullptr, settings, errorLogger); - ErrorPath errorPath; - c.assignIfError(nullptr, nullptr, emptyString, false); c.badBitmaskCheckError(nullptr); c.comparisonError(nullptr, "&", 6, "==", 1, false); - c.duplicateConditionError(nullptr, nullptr, errorPath); + c.duplicateConditionError(nullptr, nullptr, ErrorPath{}); c.overlappingElseIfConditionError(nullptr, 1); c.mismatchingBitAndError(nullptr, 0xf0, nullptr, 1); - c.oppositeInnerConditionError(nullptr, nullptr, errorPath); - c.identicalInnerConditionError(nullptr, nullptr, errorPath); - c.identicalConditionAfterEarlyExitError(nullptr, nullptr, errorPath); - c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false, errorPath); + c.oppositeInnerConditionError(nullptr, nullptr, ErrorPath{}); + c.identicalInnerConditionError(nullptr, nullptr, ErrorPath{}); + c.identicalConditionAfterEarlyExitError(nullptr, nullptr, ErrorPath{}); + c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false, ErrorPath{}); c.redundantConditionError(nullptr, "If x > 11 the condition x > 10 is always true.", false); c.moduloAlwaysTrueFalseError(nullptr, "1"); c.clarifyConditionError(nullptr, true, false); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 22a279ed87d..d3f5723ff84 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2248,7 +2248,7 @@ void CheckOther::checkDuplicateBranch() ErrorPath errorPath; if (isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand1(), branchTop2->astOperand1(), mSettings->library, true, true, &errorPath) && isSameExpression(mTokenizer->isCPP(), false, branchTop1->astOperand2(), branchTop2->astOperand2(), mSettings->library, true, true, &errorPath)) - duplicateBranchError(scope.classDef, scope.bodyEnd->next(), errorPath); + duplicateBranchError(scope.classDef, scope.bodyEnd->next(), std::move(errorPath)); } } } @@ -2570,7 +2570,7 @@ void CheckOther::checkDuplicateExpression() isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp)) duplicateValueTernaryError(tok); else if (isSameExpression(cpp, true, tok->astOperand1(), tok->astOperand2(), mSettings->library, false, true, &errorPath)) - duplicateExpressionTernaryError(tok, errorPath); + duplicateExpressionTernaryError(tok, std::move(errorPath)); } } } diff --git a/lib/checkother.h b/lib/checkother.h index 2600bb4f329..5f52e3092d9 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -293,8 +293,6 @@ class CPPCHECKLIB CheckOther : public Check { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override { CheckOther c(nullptr, settings, errorLogger); - ErrorPath errorPath; - // error c.zerodivError(nullptr, nullptr); c.misusedScopeObjectError(nullptr, "varname"); @@ -326,12 +324,12 @@ class CPPCHECKLIB CheckOther : public Check { c.selfAssignmentError(nullptr, "varname"); c.clarifyCalculationError(nullptr, "+"); c.clarifyStatementError(nullptr); - c.duplicateBranchError(nullptr, nullptr, errorPath); + c.duplicateBranchError(nullptr, nullptr, ErrorPath{}); c.duplicateAssignExpressionError(nullptr, nullptr, true); - c.oppositeExpressionError(nullptr, errorPath); - c.duplicateExpressionError(nullptr, nullptr, nullptr, errorPath); + c.oppositeExpressionError(nullptr, ErrorPath{}); + c.duplicateExpressionError(nullptr, nullptr, nullptr, ErrorPath{}); c.duplicateValueTernaryError(nullptr); - c.duplicateExpressionTernaryError(nullptr, errorPath); + c.duplicateExpressionTernaryError(nullptr, ErrorPath{}); c.duplicateBreakError(nullptr, false); c.unreachableCodeError(nullptr, nullptr, false); c.unsignedLessThanZeroError(nullptr, nullptr, "varname"); diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 708b2bf41ae..0a1d4eba5a1 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -260,11 +260,11 @@ void CheckStl::outOfBoundsError(const Token *tok, const std::string &containerNa ErrorPath errorPath1 = getErrorPath(tok, containerSize, "Access out of bounds"); ErrorPath errorPath2 = getErrorPath(tok, indexValue, "Access out of bounds"); if (errorPath1.size() <= 1) - errorPath = errorPath2; + errorPath = std::move(errorPath2); else if (errorPath2.size() <= 1) errorPath = errorPath1; else { - errorPath = errorPath1; + errorPath = std::move(errorPath1); errorPath.splice(errorPath.end(), errorPath2); } } @@ -993,7 +993,7 @@ namespace { ep.emplace_front(ftok, "After calling '" + ftok->expressionString() + "', iterators or references to the container's data may be invalid ."); - result.emplace_back(Info::Reference{tok, ep, ftok}); + result.emplace_back(Info::Reference{tok, std::move(ep), ftok}); } } return result; @@ -1165,7 +1165,7 @@ void CheckStl::invalidContainer() // Check the iterator is created before the change if (val && val->tokvalue != tok && reaches(val->tokvalue, tok, library, &ep)) { v = val; - errorPath = ep; + errorPath = std::move(ep); return true; } return false; @@ -1177,7 +1177,7 @@ void CheckStl::invalidContainer() if (v) { invalidContainerError(info.tok, r.tok, v, errorPath); } else { - invalidContainerReferenceError(info.tok, r.tok, errorPath); + invalidContainerReferenceError(info.tok, r.tok, std::move(errorPath)); } } } diff --git a/lib/checkstl.h b/lib/checkstl.h index ec476bb5156..15e265b0edd 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -243,15 +243,14 @@ class CPPCHECKLIB CheckStl : public Check { void localMutexError(const Token *tok); void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override { - ErrorPath errorPath; CheckStl c(nullptr, settings, errorLogger); c.outOfBoundsError(nullptr, "container", nullptr, "x", nullptr); c.invalidIteratorError(nullptr, "iterator"); c.iteratorsError(nullptr, "container1", "container2"); c.iteratorsError(nullptr, nullptr, "container0", "container1"); c.iteratorsError(nullptr, nullptr, "container"); - c.invalidContainerLoopError(nullptr, nullptr, errorPath); - c.invalidContainerError(nullptr, nullptr, nullptr, errorPath); + c.invalidContainerLoopError(nullptr, nullptr, ErrorPath{}); + c.invalidContainerError(nullptr, nullptr, nullptr, ErrorPath{}); c.mismatchingContainerIteratorError(nullptr, nullptr, nullptr); c.mismatchingContainersError(nullptr, nullptr); c.mismatchingContainerExpressionError(nullptr, nullptr); diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index cc2805755f6..025cc9f119f 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -117,8 +117,7 @@ class CPPCHECKLIB CheckUninitVar : public Check { void uninitdataError(const Token *tok, const std::string &varname); void uninitvarError(const Token *tok, const std::string &varname, ErrorPath errorPath); void uninitvarError(const Token *tok, const std::string &varname) { - ErrorPath errorPath; - uninitvarError(tok, varname, errorPath); + uninitvarError(tok, varname, ErrorPath{}); } void uninitvarError(const Token *tok, const std::string &varname, Alloc alloc) { if (alloc == NO_CTOR_CALL || alloc == CTOR_CALL) diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index eb789fdf727..f4072d70f5d 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -363,7 +363,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger, locationList.back().fileIndex = fileIndex; } - const ErrorMessage errmsg(locationList, emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal); + const ErrorMessage errmsg(std::move(locationList), emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal); if (errorLogger) errorLogger->reportErr(errmsg); else diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 0f83af6d697..54c212ec2b8 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -947,7 +947,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList) --addrIndex; const std::string addr = mExtTokens[addrIndex]; std::string name = unquote(getSpelling()); - Token *reftok = addtoken(tokenList, name.empty() ? "" : name); + Token *reftok = addtoken(tokenList, name.empty() ? "" : std::move(name)); mData->ref(addr, reftok); return reftok; } @@ -1085,10 +1085,10 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList) Token *par2 = addtoken(tokenList, ")"); par1->link(par2); par2->link(par1); - createScope(tokenList, Scope::ScopeType::eIf, thenCode, iftok); + createScope(tokenList, Scope::ScopeType::eIf, std::move(thenCode), iftok); if (elseCode) { elseCode->addtoken(tokenList, "else"); - createScope(tokenList, Scope::ScopeType::eElse, elseCode, tokenList.back()); + createScope(tokenList, Scope::ScopeType::eElse, std::move(elseCode), tokenList.back()); } return nullptr; } @@ -1255,7 +1255,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList) Token *par2 = addtoken(tokenList, ")"); par1->link(par2); par2->link(par1); - createScope(tokenList, Scope::ScopeType::eWhile, body, whiletok); + createScope(tokenList, Scope::ScopeType::eWhile, std::move(body), whiletok); return nullptr; } return addtoken(tokenList, "?" + nodeType + "?"); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 14e5543b327..cf0c99df3da 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -289,7 +289,7 @@ static std::vector executeAddon(const AddonInfo &addonInfo, if (pos != std::string::npos) details.resize(pos + 1); } - throw InternalError(nullptr, message, details); + throw InternalError(nullptr, std::move(message), std::move(details)); } std::vector addonResult; @@ -666,7 +666,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string const ErrorMessage::FileLocation loc1(file, output.location.line, output.location.col); std::list callstack(1, loc1); - ErrorMessage errmsg(callstack, + ErrorMessage errmsg(std::move(callstack), "", Severity::error, output.msg, @@ -1043,7 +1043,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg const ErrorMessage::FileLocation loc1(filename, 0, 0); std::list callstack(1, loc1); - ErrorMessage errmsg(callstack, + ErrorMessage errmsg(std::move(callstack), emptyString, Severity::error, fullmsg, @@ -1553,7 +1553,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo msg << " For more details, use --enable=information."; - ErrorMessage errmsg(loclist, + ErrorMessage errmsg(std::move(loclist), emptyString, Severity::information, msg.str(), @@ -1575,7 +1575,7 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st loclist.emplace_back(file); } - ErrorMessage errmsg(loclist, + ErrorMessage errmsg(std::move(loclist), emptyString, Severity::information, "The configuration '" + configuration + "' was not checked because its code equals another one.", @@ -1758,7 +1758,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings) else errmsg.severity = Severity::style; - errmsg.file0 = fixedpath; + errmsg.file0 = std::move(fixedpath); errmsg.setmsg(messageString); reportErr(errmsg); } diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index fbb635c691d..8ec05204a62 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -337,7 +337,7 @@ void ErrorMessage::deserialize(const std::string &data) } } - results[elem++] = temp; + results[elem++] = std::move(temp); } if (!iss.good()) diff --git a/lib/importproject.cpp b/lib/importproject.cpp index d43d490d792..57e0fdff127 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -337,7 +337,7 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command) // we can only set it globally but in this context it needs to be treated per file } } - fsSetDefines(fs, defs); + fsSetDefines(fs, std::move(defs)); } bool ImportProject::importCompileCommands(std::istream &istr) @@ -630,7 +630,7 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::mapAttribute("action"); Container::Action action = Container::Action::NO_ACTION; diff --git a/lib/pathanalysis.cpp b/lib/pathanalysis.cpp index b15bffb95d4..045c0f50803 100644 --- a/lib/pathanalysis.cpp +++ b/lib/pathanalysis.cpp @@ -76,7 +76,7 @@ PathAnalysis::Progress PathAnalysis::forwardRecursive(const Token* tok, Info inf info.tok = tok; if (f(info) == Progress::Break) return Progress::Break; - if (tok->astOperand2() && forwardRecursive(tok->astOperand2(), info, f) == Progress::Break) + if (tok->astOperand2() && forwardRecursive(tok->astOperand2(), std::move(info), f) == Progress::Break) return Progress::Break; return Progress::Continue; } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index b07d644aacb..93175118612 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -552,7 +552,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set } configs_if.push_back((cmdtok->str() == "ifndef") ? std::string() : config); - configs_ifndef.push_back((cmdtok->str() == "ifndef") ? config : std::string()); + configs_ifndef.push_back((cmdtok->str() == "ifndef") ? std::move(config) : std::string()); ret.insert(cfg(configs_if,userDefines)); } else if (cmdtok->str() == "elif" || cmdtok->str() == "else") { if (getConfigsElseIsFalse(configs_if,userDefines)) { @@ -831,7 +831,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens std::list ifCond; simplecpp::TokenList tokens2(files); simplecpp::preprocess(tokens2, tokens1, files, mTokenLists, dui, &outputList, ¯oUsage, &ifCond); - mMacroUsage = macroUsage; + mMacroUsage = std::move(macroUsage); mIfCond = ifCond; handleErrors(outputList, throwError); @@ -910,7 +910,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const ErrorMessage::FileLocation loc(file, linenr, 0); locationList.push_back(std::move(loc)); } - mErrorLogger->reportErr(ErrorMessage(locationList, + mErrorLogger->reportErr(ErrorMessage(std::move(locationList), mFile0, Severity::error, msg, diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index b69df63a5cb..1b160bc1c3d 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -1227,7 +1227,7 @@ static bool evalSameCondition(const ProgramMemory& state, programMemoryParseCondition(pm, storedValue, nullptr, settings, true); if (pm == state) return false; - return conditionIsTrue(cond, pm, settings); + return conditionIsTrue(cond, std::move(pm), settings); } static void pruneConditions(std::vector& conds, diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index d13ba5705fe..f2ee9a6bf9e 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -557,7 +557,7 @@ bool Suppressions::reportUnmatchedSuppressions(const std::list callStack; if (!s.fileName.empty()) callStack.emplace_back(s.fileName, s.lineNumber, 0); - errorLogger.reportErr(::ErrorMessage(callStack, emptyString, Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal)); + errorLogger.reportErr(::ErrorMessage(std::move(callStack), emptyString, Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal)); err = true; } return err; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 3f54a849a99..098154ff8e4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -549,7 +549,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // out of line function if (const Token *endTok = Tokenizer::isFunctionHead(end, ";")) { tok = endTok; - scope->addFunction(function); + scope->addFunction(std::move(function)); } // inline function @@ -3028,7 +3028,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se } } - param = short_path; + param = std::move(short_path); if (Token::simpleMatch(second->next(), param.c_str(), param.size())) { second = second->tokAt(int(short_path_length)); arg_path_length = 0; diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 22d2e234fb0..943779b7b7f 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -994,7 +994,7 @@ void TemplateSimplifier::getTemplateInstantiations() std::string fullNameSpace = scopeName + (scopeName.empty()?"":" :: ") + nameSpace + (qualification.empty()?"":" :: ") + qualification; std::string newFullName = fullNameSpace + " :: " + tok->str(); - const std::list::const_iterator it1 = std::find_if(mTemplateDeclarations.cbegin(), mTemplateDeclarations.cend(), FindFullName(newFullName)); + const std::list::const_iterator it1 = std::find_if(mTemplateDeclarations.cbegin(), mTemplateDeclarations.cend(), FindFullName(std::move(newFullName))); if (it1 != mTemplateDeclarations.end()) { // insert using namespace into token stream std::string::size_type offset = 0; @@ -2229,7 +2229,7 @@ void TemplateSimplifier::expandTemplate( if (end != std::string::npos) { token_scope.resize(end); if (scope.empty()) - scope = token_scope; + scope = std::move(token_scope); else scope = token_scope + " :: " + scope; } diff --git a/lib/token.cpp b/lib/token.cpp index 7e35af1e2d0..445ac26ac22 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1223,7 +1223,7 @@ Token* Token::insertToken(const std::string& tokenStr, const std::string& origin newScopeInfo->name.append(nextScopeNameAddition); nextScopeNameAddition = ""; - newToken->scopeInfo(newScopeInfo); + newToken->scopeInfo(std::move(newScopeInfo)); } else if (newToken->str() == "}") { Token* matchingTok = newToken->previous(); int depth = 0; @@ -2136,7 +2136,7 @@ static ValueIterator removeAdjacentValues(std::list& values, V if (it == last) it--; (*it)->bound = x->bound; - std::for_each(start, it, [&](ValueIterator y) { + std::for_each(std::move(start), std::move(it), [&](ValueIterator y) { values.erase(y); }); return values.erase(x); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a549f0b80f3..6bdee6618dc 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2624,7 +2624,7 @@ namespace { if (tok && tok->str() == "{") { *scopeInfo = (*scopeInfo)->addChild(record ? ScopeInfo3::Record : ScopeInfo3::Namespace, classname, tok, tok->link()); - (*scopeInfo)->baseTypes = baseTypes; + (*scopeInfo)->baseTypes = std::move(baseTypes); } } @@ -3234,7 +3234,7 @@ bool Tokenizer::simplifyUsing() } } else { // add some qualification back if needed - std::string removed1 = removed; + std::string removed1 = std::move(removed); std::string::size_type idx = removed1.rfind(" ::"); if (idx != std::string::npos) removed1.resize(idx); @@ -3990,7 +3990,7 @@ void Tokenizer::calculateScopes() std::string nextScopeNameAddition; std::shared_ptr primaryScope = std::make_shared("", nullptr); - list.front()->scopeInfo(primaryScope); + list.front()->scopeInfo(std::move(primaryScope)); for (Token* tok = list.front(); tok; tok = tok->next()) { if (tok == list.front() || !tok->scopeInfo()) { @@ -4068,7 +4068,7 @@ void Tokenizer::calculateScopes() if (tok->link()) tok->link()->scopeInfo(tok->scopeInfo()); - tok->scopeInfo(newScopeInfo); + tok->scopeInfo(std::move(newScopeInfo)); } } } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 7ed5f27b48b..cda431b17d9 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -133,7 +133,7 @@ static void bailoutInternal(const std::string& type, const TokenList &tokenlist, function = "(valueFlow)"; std::list callstack(1, ErrorMessage::FileLocation(tok, &tokenlist)); const std::string location = Path::stripDirectoryPart(file) + ":" + std::to_string(line) + ":"; - ErrorMessage errmsg(callstack, tokenlist.getSourceFilePath(), Severity::debug, + ErrorMessage errmsg(std::move(callstack), tokenlist.getSourceFilePath(), Severity::debug, (file.empty() ? "" : location) + function + " bailout: " + what, type, Certainty::normal); errorLogger->reportErr(errmsg); } @@ -811,7 +811,7 @@ static void setTokenValue(Token* tok, v.conditional = true; v.changeKnownToPossible(); - setTokenValue(parent, v, settings); + setTokenValue(parent, std::move(v), settings); } } @@ -927,7 +927,7 @@ static void setTokenValue(Token* tok, } else { continue; } - setTokenValue(parent, result, settings); + setTokenValue(parent, std::move(result), settings); } else if (Token::Match(parent, "%op%")) { if (Token::Match(parent, "%comp%")) { if (!result.isFloatValue() && !value1.isIntValue() && !value2.isIntValue()) @@ -1047,7 +1047,7 @@ static void setTokenValue(Token* tok, const Token* lhs = parent->previous()->astOperand1(); if (lhs && lhs->valueType()) { if (lhs->valueType()->isIntegral() || lhs->valueType()->isFloat() || (lhs->valueType()->pointer > 0 && value.isIntValue())) { - setTokenValue(parent, value, settings); + setTokenValue(parent, std::move(value), settings); } } } @@ -1622,7 +1622,7 @@ static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings setTokenValue(tok, result, settings); } else if (index >= 0 && index < s.size()) { result.intvalue = s[index]; - setTokenValue(tok, result, settings); + setTokenValue(tok, std::move(result), settings); } } else if (Token::simpleMatch(arrayValue.tokvalue, "{")) { std::vector args = getArguments(arrayValue.tokvalue); @@ -2960,7 +2960,7 @@ struct ValueFlowAnalyzer : Analyzer { if (Token::Match(tok, "&&|%oror%")) { if (conditionIsTrue(tok, pm, &getSettings())) result.push_back(1); - if (conditionIsFalse(tok, pm, &getSettings())) + if (conditionIsFalse(tok, std::move(pm), &getSettings())) result.push_back(0); } else { MathLib::bigint out = 0; @@ -4028,7 +4028,7 @@ static void valueFlowForwardLifetime(Token * tok, TokenList &tokenlist, ErrorLog Token *nextExpression = nextAfterAstRightmostLeaf(parent); // Only forward lifetime values values.remove_if(&isNotLifetimeValue); - valueFlowForward(nextExpression, endOfVarScope, tok, values, tokenlist, errorLogger, settings); + valueFlowForward(nextExpression, endOfVarScope, tok, std::move(values), tokenlist, errorLogger, settings); // Cast } else if (parent->isCast()) { std::list values = tok->values(); @@ -5057,7 +5057,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, co value.tokvalue = rt.token; value.errorPath.insert(value.errorPath.begin(), rt.errors.cbegin(), rt.errors.cend()); if (Token::simpleMatch(parent, "(")) - setTokenValue(parent, value, settings); + setTokenValue(parent, std::move(value), settings); else setTokenValue(parent->tokAt(2), value, settings); @@ -5106,7 +5106,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, co value.valueType = ValueFlow::Value::ValueType::LIFETIME; value.lifetimeScope = ValueFlow::Value::LifetimeScope::Local; value.tokvalue = var->nameToken(); - value.errorPath = errorPath; + value.errorPath = std::move(errorPath); setTokenValue(tok, std::move(value), settings); valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings); @@ -5498,13 +5498,13 @@ static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase& rhs.errorPath.emplace_back(tok, tok->astOperand1()->expressionString() + " is assigned '" + tok->astOperand2()->expressionString() + "' here."); - valueFlowForward(start, end, tok->astOperand1(), rhs, tokenlist, errorLogger, settings); + valueFlowForward(start, end, tok->astOperand1(), std::move(rhs), tokenlist, errorLogger, settings); ValueFlow::Value lhs = makeSymbolic(tok->astOperand1()); lhs.errorPath.emplace_back(tok, tok->astOperand1()->expressionString() + " is assigned '" + tok->astOperand2()->expressionString() + "' here."); - valueFlowForward(start, end, tok->astOperand2(), lhs, tokenlist, errorLogger, settings); + valueFlowForward(start, end, tok->astOperand2(), std::move(lhs), tokenlist, errorLogger, settings); } } } @@ -5900,11 +5900,11 @@ static void valueFlowForwardAssign(Token* const tok, value.bound = b; value.invertRange(); value.setImpossible(); - valueFlowForwardConst(nextExpression, endOfVarScope, expr->variable(), {value}, settings); + valueFlowForwardConst(nextExpression, endOfVarScope, expr->variable(), {std::move(value)}, settings); } } } - valueFlowForward(nextExpression, endOfVarScope, expr, values, tokenlist, errorLogger, settings); + valueFlowForward(nextExpression, endOfVarScope, expr, std::move(values), tokenlist, errorLogger, settings); } static void valueFlowForwardAssign(Token* const tok, @@ -6080,7 +6080,7 @@ static void valueFlowAfterAssign(TokenList &tokenlist, continue; const bool init = vars.size() == 1 && (vars.front()->nameToken() == tok->astOperand1() || tok->isSplittedVarDeclEq()); valueFlowForwardAssign( - rhs, tok->astOperand1(), vars, values, init, tokenlist, errorLogger, settings); + rhs, tok->astOperand1(), std::move(vars), values, init, tokenlist, errorLogger, settings); // Back propagate symbolic values if (tok->astOperand1()->exprId() > 0) { Token* start = nextAfterAstRightmostLeaf(tok); @@ -6112,7 +6112,7 @@ static void valueFlowAfterAssign(TokenList &tokenlist, value.errorPath.emplace_back(tok, tok->astOperand1()->expressionString() + " is assigned '" + tok->astOperand2()->expressionString() + "' here."); - valueFlowForward(start, end, expr, value, tokenlist, errorLogger, settings); + valueFlowForward(start, end, expr, std::move(value), tokenlist, errorLogger, settings); } } } @@ -6151,7 +6151,7 @@ static void valueFlowAfterSwap(TokenList& tokenlist, for (int i = 0; i < 2; i++) { std::vector vars = getVariables(args[0]); const std::list& values = args[0]->values(); - valueFlowForwardAssign(args[0], args[1], vars, values, false, tokenlist, errorLogger, settings); + valueFlowForwardAssign(args[0], args[1], std::move(vars), values, false, tokenlist, errorLogger, settings); std::swap(args[0], args[1]); } } @@ -6529,7 +6529,7 @@ struct ConditionHandler { if (op == "&&") values = andValues; else if (op == "||") - values = orValues; + values = std::move(orValues); if (allowKnown && (Token::Match(condTok, "==|!=") || cond.isBool())) changePossibleToKnown(values); if (astIsFloat(cond.vartok, false) || @@ -6750,9 +6750,9 @@ struct ConditionHandler { std::list values; if (dead_if) { - values = elseValues; + values = std::move(elseValues); } else if (dead_else) { - values = thenValues; + values = std::move(thenValues); } else { std::copy_if(thenValues.cbegin(), thenValues.cend(), @@ -7246,7 +7246,7 @@ static void valueFlowForLoopSimplifyAfter(Token* fortok, nonneg int varid, const ValueFlow::Value v{num}; v.errorPath.emplace_back(fortok,"After for loop, " + var->name() + " has value " + v.infoString()); - valueFlowForward(blockTok->next(), endToken, vartok, v, tokenlist, errorLogger, settings); + valueFlowForward(blockTok->next(), endToken, vartok, std::move(v), tokenlist, errorLogger, settings); } } @@ -7274,7 +7274,7 @@ static void valueFlowForLoop(TokenList &tokenlist, const SymbolDatabase& symbold std::list initValues; initValues.emplace_back(initValue, ValueFlow::Value::Bound::Lower); initValues.push_back(ValueFlow::asImpossible(initValues.back())); - Analyzer::Result result = valueFlowForward(bodyStart, bodyStart->link(), vartok, initValues, tokenlist, errorLogger, settings); + Analyzer::Result result = valueFlowForward(bodyStart, bodyStart->link(), vartok, std::move(initValues), tokenlist, errorLogger, settings); if (!result.action.isModified()) { std::list lastValues; @@ -7283,7 +7283,7 @@ static void valueFlowForLoop(TokenList &tokenlist, const SymbolDatabase& symbold lastValues.push_back(ValueFlow::asImpossible(lastValues.back())); if (stepValue != 1) lastValues.pop_front(); - valueFlowForward(bodyStart, bodyStart->link(), vartok, lastValues, tokenlist, errorLogger, settings); + valueFlowForward(bodyStart, bodyStart->link(), vartok, std::move(lastValues), tokenlist, errorLogger, settings); } } const MathLib::bigint afterValue = executeBody ? lastValue + stepValue : initValue; @@ -7784,7 +7784,7 @@ static void valueFlowSubFunction(TokenList& tokenlist, SymbolDatabase& symboldat // passed values are not "known".. lowerToPossible(argvalues); - argvars[argvar] = argvalues; + argvars[argvar] = std::move(argvalues); } valueFlowInjectParameter(tokenlist, errorLogger, settings, calledFunctionScope, argvars); } @@ -8101,7 +8101,7 @@ static void valueFlowUninit(TokenList& tokenlist, ErrorLogger* const errorLogger if (partial) continue; - valueFlowForward(start, tok->scope()->bodyEnd, var->nameToken(), uninitValue, tokenlist, errorLogger, settings); + valueFlowForward(start, tok->scope()->bodyEnd, var->nameToken(), std::move(uninitValue), tokenlist, errorLogger, settings); } } @@ -8484,7 +8484,7 @@ static void valueFlowSmartPointer(TokenList &tokenlist, ErrorLogger * errorLogge continue; ValueFlow::Value v(0); v.setKnown(); - valueFlowForwardAssign(ftok, tok, vars, {std::move(v)}, false, tokenlist, errorLogger, settings); + valueFlowForwardAssign(ftok, tok, std::move(vars), {std::move(v)}, false, tokenlist, errorLogger, settings); } else if (Token::simpleMatch(tok->astParent(), ". get ( )")) { ValueFlow::Value v = makeSymbolic(tok); setTokenValue(tok->astParent()->tokAt(2), std::move(v), settings); @@ -8570,7 +8570,7 @@ struct IteratorConditionHandler : SimpleConditionHandler { v.assumeCondition(tok); } cond.true_values = values; - cond.false_values = values; + cond.false_values = std::move(values); } return {std::move(cond)}; @@ -8751,7 +8751,7 @@ static void valueFlowContainerSetTokValue(TokenList& tokenlist, ErrorLogger* con if (tok->variable() && tok->variable()->isConst()) { valueFlowForwardConst(start, tok->variable()->scope()->bodyEnd, tok->variable(), {value}, settings); } else { - valueFlowForward(start, tok, value, tokenlist, errorLogger, settings); + valueFlowForward(start, tok, std::move(value), tokenlist, errorLogger, settings); } } @@ -8904,7 +8904,7 @@ static void valueFlowContainerSize(TokenList& tokenlist, ValueFlow::Value value(0); value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; value.setKnown(); - valueFlowForward(tok->next(), containerTok, value, tokenlist, errorLogger, settings); + valueFlowForward(tok->next(), containerTok, std::move(value), tokenlist, errorLogger, settings); } else if (action == Library::Container::Action::RESIZE && tok->tokAt(2)->astOperand2() && tok->tokAt(2)->astOperand2()->hasKnownIntValue()) { ValueFlow::Value value(tok->tokAt(2)->astOperand2()->values().front()); @@ -9264,7 +9264,7 @@ static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase& s valueFlowForward(const_cast(functionScope->bodyStart->next()), functionScope->bodyEnd, arg.nameToken(), - argValues, + std::move(argValues), tokenlist, errorLogger, settings);