diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 23de733c7a4..2d855e6b984 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -1207,7 +1207,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a for (;;) { const std::string::size_type pos = paths.find(';'); if (pos == std::string::npos) { - mSettings.basePaths.emplace_back(Path::fromNativeSeparators(paths)); + mSettings.basePaths.emplace_back(Path::fromNativeSeparators(std::move(paths))); break; } mSettings.basePaths.emplace_back(Path::fromNativeSeparators(paths.substr(0, pos))); diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 7440388b57f..db4fd2d27e8 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -638,7 +638,7 @@ void StdLogger::reportErr(const ErrorMessage &msg) msgCopy.classification = getClassification(msgCopy.guideline, mSettings.reportType); if (mSettings.outputFormat == Settings::OutputFormat::sarif) - mSarifReport.addFinding(msgCopy); + mSarifReport.addFinding(std::move(msgCopy)); else if (mSettings.xml) reportErr(msgCopy.toXML()); else diff --git a/lib/addoninfo.cpp b/lib/addoninfo.cpp index da5fc2536f5..217f04ae532 100644 --- a/lib/addoninfo.cpp +++ b/lib/addoninfo.cpp @@ -115,10 +115,10 @@ static std::string parseAddonInfo(AddonInfo& addoninfo, const picojson::value &j const auto& val = it->second; if (!val.is()) return "Loading " + fileName + " failed. 'executable' must be a string."; - const std::string e = val.get(); + std::string e = val.get(); addoninfo.executable = getFullPath(e, fileName); if (addoninfo.executable.empty()) - addoninfo.executable = e; + addoninfo.executable = std::move(e); return ""; // <- do not load both "executable" and "script". } } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 25a23c70bc1..bcab63f7e4f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1438,8 +1438,8 @@ void CheckClass::checkMemset() alloc = mSettings->library.getReallocFuncInfo(tok->tokAt(2)); if (!alloc || alloc->bufferSize == Library::AllocFunc::BufferSize::none) continue; - const std::set parsedTypes; - checkMemsetType(scope, tok->tokAt(2), tok->variable()->typeScope(), true, parsedTypes); + std::set parsedTypes; + checkMemsetType(scope, tok->tokAt(2), tok->variable()->typeScope(), true, std::move(parsedTypes)); if (printWarnings && tok->variable()->typeScope()->numConstructors > 0) mallocOnClassWarning(tok, tok->strAt(2), tok->variable()->typeScope()->classDef); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 27e49528571..31f8aad95c6 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -735,13 +735,13 @@ void CheckOther::redundantBitwiseOperationInSwitchError() else if (Token::Match(tok2->previous(), ";|{|}|: %var% %assign% %num% ;") && (tok2->strAt(1) == "|=" || tok2->strAt(1) == "&=") && Token::Match(tok2->next()->astOperand2(), "%num%")) { - const std::string bitOp = tok2->strAt(1)[0] + tok2->strAt(2); + std::string bitOp = tok2->strAt(1)[0] + tok2->strAt(2); const auto i2 = utils::as_const(varsWithBitsSet).find(tok2->varId()); // This variable has not had a bit operation performed on it yet, so just make a note of it if (i2 == varsWithBitsSet.end()) { varsWithBitsSet[tok2->varId()] = tok2; - bitOperations[tok2->varId()] = bitOp; + bitOperations[tok2->varId()] = std::move(bitOp); } // The same bit operation has been performed on the same variable twice, so report an error diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 25fbd9a63aa..6d25124dcc4 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -277,7 +277,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const Setting if (funcname) { if (isRecursiveCall(funcname)) continue; - const auto baseName = stripTemplateParameters(funcname->str()); + auto baseName = stripTemplateParameters(funcname->str()); FunctionUsage &func = mFunctions[baseName]; const std::string& called_from_file = tokenizer.list.getFiles()[funcname->fileIndex()]; @@ -286,7 +286,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const Setting else func.usedSameFile = true; - mFunctionCalls.insert(baseName); + mFunctionCalls.insert(std::move(baseName)); } } } diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index ba5fee3acd2..01db6a8850f 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1298,7 +1298,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() typeName.erase(typeName.begin(), typeName.begin() + 2); switch (mSettings->library.getTypeCheck("unusedvar", typeName)) { case Library::TypeCheck::def: - bailoutTypeName = typeName; + bailoutTypeName = std::move(typeName); break; case Library::TypeCheck::check: break; diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 942c3ba988e..d7348109997 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -678,9 +678,9 @@ void clangimport::AstNode::setValueType(Token *tok) if (!decl.front()) break; - const ValueType valueType = ValueType::parseDecl(decl.front(), *mData->mSettings); + ValueType valueType = ValueType::parseDecl(decl.front(), *mData->mSettings); if (valueType.type != ValueType::Type::UNKNOWN_TYPE) { - tok->setValueType(new ValueType(valueType)); + tok->setValueType(new ValueType(std::move(valueType))); break; } } diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index fa4c205110f..8a9641d6427 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -432,8 +432,6 @@ static std::vector executeAddon(const AddonInfo &addonInfo, const std::string &premiumArgs, const CppCheck::ExecuteCmdFn &executeCommand) { - const std::string redirect = "2>&1"; - std::string pythonExe; if (!addonInfo.executable.empty()) @@ -462,7 +460,7 @@ static std::vector executeAddon(const AddonInfo &addonInfo, args += fileArg; std::string result; - if (const int exitcode = executeCommand(pythonExe, split(args), redirect, result)) { + if (const int exitcode = executeCommand(pythonExe, split(args), "2>&1", result)) { std::string message("Failed to execute addon '" + addonInfo.name + "' - exitcode is " + std::to_string(exitcode)); std::string details = pythonExe + " " + args; if (result.size() > 2) { @@ -580,17 +578,17 @@ static bool reportClangErrors(std::istream &is, const std::function= pos2 || pos2 >= pos3) continue; - const std::string filename = line.substr(0, pos1); + std::string filename = line.substr(0, pos1); const std::string linenr = line.substr(pos1+1, pos2-pos1-1); const std::string colnr = line.substr(pos2+1, pos3-pos2-1); const std::string msg = line.substr(line.find(':', pos3+1) + 2); - const std::string locFile = Path::toNativeSeparators(filename); + std::string locFile = Path::toNativeSeparators(std::move(filename)); const int line_i = strToInt(linenr); const int column = strToInt(colnr); ErrorMessage::FileLocation loc(locFile, line_i, column); ErrorMessage errmsg({std::move(loc)}, - locFile, + std::move(locFile), Severity::error, msg, "syntaxError", @@ -1230,10 +1228,10 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string for (const std::string &s : configurationError) msg += '\n' + s; - const std::string locFile = Path::toNativeSeparators(file.spath()); + std::string locFile = Path::toNativeSeparators(file.spath()); ErrorMessage::FileLocation loc(locFile, 0, 0); ErrorMessage errmsg({std::move(loc)}, - locFile, + std::move(locFile), Severity::information, msg, "noValidConfiguration", @@ -1777,13 +1775,13 @@ void CppCheck::executeAddonsWholeProgram(const std::list &files return; if (mSettings.buildDir.empty()) { - const std::string fileName = std::to_string(mSettings.pid) + ".ctu-info"; + std::string fileName = std::to_string(mSettings.pid) + ".ctu-info"; FilesDeleter filesDeleter; filesDeleter.addFile(fileName); std::ofstream fout(fileName); fout << ctuInfo; fout.close(); - executeAddons({fileName}, ""); + executeAddons({std::move(fileName)}, ""); return; } diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 498eb22456a..8dea2b3d696 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -290,7 +290,7 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command) while (pos < command.size() && command[pos] == ' ') ++pos; } - const std::string fval = readUntil(command, &pos, " ="); + std::string fval = readUntil(command, &pos, " ="); if (F=='D') { std::string defval = readUntil(command, &pos, " "); defs += fval; @@ -304,7 +304,7 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command) } else if (F=='U') fs.undefs.insert(fval); else if (F=='I') { - std::string i = fval; + std::string i = std::move(fval); if (i.size() > 1 && i[0] == '\"' && i.back() == '\"') i = unescape(i.substr(1, i.size() - 2)); if (std::find(fs.includePaths.cbegin(), fs.includePaths.cend(), i) == fs.includePaths.cend()) @@ -394,7 +394,7 @@ bool ImportProject::importCompileCommands(std::istream &istr) continue; } - const std::string file = Path::fromNativeSeparators(obj["file"].get()); + std::string file = Path::fromNativeSeparators(obj["file"].get()); // Accept file? if (!Path::acceptFile(file)) @@ -402,7 +402,7 @@ bool ImportProject::importCompileCommands(std::istream &istr) std::string path; if (Path::isAbsolute(file)) - path = Path::simplifyPath(file); + path = Path::simplifyPath(std::move(file)); #ifdef _WIN32 else if (file[0] == '/' && directory.size() > 2 && std::isalpha(directory[0]) && directory[1] == ':') // directory: C:\foo\bar @@ -1009,7 +1009,7 @@ bool ImportProject::importBcb6Prj(const std::string &projectFilename) } if (!arg.empty()) { - cflags.insert(arg); + cflags.insert(std::move(arg)); } // cleanup: -t is "An alternate name for the -Wxxx switches; there is no difference" diff --git a/lib/summaries.cpp b/lib/summaries.cpp index a893b13a0aa..bcedbb9fc2b 100644 --- a/lib/summaries.cpp +++ b/lib/summaries.cpp @@ -173,9 +173,8 @@ void Summaries::loadReturn(const std::string &buildDir, std::set &s // Get function name constexpr std::string::size_type pos1 = 0; const std::string::size_type pos2 = line.find(' ', pos1); - const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2); + std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2); std::vector call = getSummaryData(line, "call"); - functionCalls[functionName] = call; if (call.empty()) return1.push_back(functionName); else { @@ -183,6 +182,7 @@ void Summaries::loadReturn(const std::string &buildDir, std::set &s functionCalledBy[c].push_back(functionName); } } + functionCalls[functionName] = std::move(call); } } summaryReturn.insert(return1.cbegin(), return1.cend()); diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index d5a10d8176e..7bb69f90ab2 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -139,7 +139,7 @@ std::string SuppressionList::parseXmlFile(const char *filename) return std::string("unknown element '") + name + "' in suppressions XML '" + filename + "', expected id/fileName/lineNumber/symbolName/hash."; } - const std::string err = addSuppression(std::move(s)); + std::string err = addSuppression(std::move(s)); if (!err.empty()) return err; } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 65c70b12b8b..b13817e95ec 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5956,7 +5956,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen // sort according to matching arguments std::sort(fallback1Func.begin(), fallback1Func.end(), fb_pred); std::sort(fallback2Func.begin(), fallback2Func.end(), fb_pred); - for (const auto& fb : { fallback1Func, fallback2Func }) { + const auto fallbackFuncs = { std::move(fallback1Func), std::move(fallback2Func) }; + for (const auto& fb : fallbackFuncs) { if (fb.size() == 1) return fb[0].first; if (fb.size() >= 2) { @@ -5985,7 +5986,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen return matches[0]; // Prioritize matches in derived scopes - for (const auto& fb : { fallback1Func, fallback2Func }) { + for (const auto& fb : fallbackFuncs) { const Function* ret = nullptr; for (std::size_t i = 0; i < fb.size(); ++i) { if (std::find(matches.cbegin(), matches.cend(), fb[i].first) == matches.cend()) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index c48217928ed..09753c662b6 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -993,9 +993,9 @@ void TemplateSimplifier::getTemplateInstantiations() // Add outer template.. if (templateParameters(tok->next()) || tok->strAt(2) == ">") { while (true) { - const std::string fullName = scopeName + (scopeName.empty()?"":" :: ") + - qualification + (qualification.empty()?"":" :: ") + tok->str(); - const auto it = std::find_if(mTemplateDeclarations.cbegin(), mTemplateDeclarations.cend(), FindFullName(fullName)); + std::string fullName = scopeName + (scopeName.empty()?"":" :: ") + + qualification + (qualification.empty()?"":" :: ") + tok->str(); + const auto it = std::find_if(mTemplateDeclarations.cbegin(), mTemplateDeclarations.cend(), FindFullName(std::move(fullName))); if (it != mTemplateDeclarations.end()) { // full name matches addInstantiation(tok, it->scope()); @@ -3314,9 +3314,9 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( // New classname/funcname.. const std::string newName(templateDeclaration.name() + " < " + typeForNewName + " >"); - const std::string newFullName(templateDeclaration.scope() + (templateDeclaration.scope().empty() ? "" : " :: ") + newName); + std::string newFullName(templateDeclaration.scope() + (templateDeclaration.scope().empty() ? "" : " :: ") + newName); - if (expandedtemplates.insert(newFullName).second) { + if (expandedtemplates.insert(std::move(newFullName)).second) { expandTemplate(templateDeclaration, templateDeclaration, typeParametersInDeclaration, newName, !specialized && !isVar); instantiated = true; mChanged = true; diff --git a/lib/token.cpp b/lib/token.cpp index aea4c3a713f..9b609390079 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1162,7 +1162,7 @@ Token* Token::insertToken(const std::string& tokenStr, const std::string& origin nameSpace += tok1->str(); tok1 = tok1->next(); } - mImpl->mScopeInfo->usingNamespaces.insert(nameSpace); + mImpl->mScopeInfo->usingNamespaces.insert(std::move(nameSpace)); } } } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5fbb30a4f2f..d5c7e3071e8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5177,9 +5177,9 @@ void Tokenizer::setVarIdPass2() } std::string scopeName3(scopeName2); while (!scopeName3.empty()) { - const std::string name = scopeName3 + baseClassName; + std::string name = scopeName3 + baseClassName; if (varsByClass.find(name) != varsByClass.end()) { - baseClassName = name; + baseClassName = std::move(name); break; } // Remove last scope name diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9f5254b02c7..41515b1eada 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1071,7 +1071,7 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett ValueFlow::Value symValue{}; symValue.valueType = ValueFlow::Value::ValueType::SYMBOLIC; symValue.tokvalue = tok2; - values.push_back(symValue); + values.push_back(std::move(symValue)); std::copy_if(tok2->values().cbegin(), tok2->values().cend(), std::back_inserter(values), @@ -7155,10 +7155,10 @@ struct ValueFlowPassRunner { if (state.settings.severity.isEnabled(Severity::information)) { const std::string& functionName = functionScope->className; - const std::list callstack( + std::list callstack( 1, ErrorMessage::FileLocation(functionScope->bodyStart, &state.tokenlist)); - const ErrorMessage errmsg(callstack, + const ErrorMessage errmsg(std::move(callstack), state.tokenlist.getSourceFilePath(), Severity::information, "Limiting ValueFlow analysis in function '" + functionName + "' since it is too complex. "