From b65b47d3a853b6f154e2d797bef36ed7a9a03484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Thu, 28 Jul 2022 22:51:45 +0200 Subject: [PATCH] enabled and fixed `modernize-pass-by-value` clang-tidy warnings (#4169) --- .clang-tidy | 2 +- gui/application.cpp | 10 +++---- gui/application.h | 2 +- gui/codeeditorstyle.cpp | 47 +++++++++++++++++++------------- gui/codeeditorstyle.h | 24 ++++++++++------ gui/projectfile.cpp | 4 +-- gui/projectfile.h | 2 +- gui/report.cpp | 4 +-- gui/report.h | 2 +- lib/checkunusedfunctions.cpp | 2 +- lib/clangimport.cpp | 4 +-- lib/cppcheck.cpp | 2 +- lib/errorlogger.cpp | 53 ++++++++++-------------------------- lib/errorlogger.h | 18 ++++++------ lib/errortypes.cpp | 25 +++++++++++++++++ lib/errortypes.h | 2 +- lib/importproject.cpp | 2 +- lib/pathmatch.cpp | 4 +-- lib/pathmatch.h | 2 +- lib/preprocessor.cpp | 6 ++-- lib/preprocessor.h | 2 +- lib/templatesimplifier.cpp | 14 +++++----- lib/templatesimplifier.h | 4 +-- lib/timer.cpp | 4 +-- lib/timer.h | 2 +- lib/tokenize.cpp | 6 ++-- lib/valueflow.cpp | 6 ++-- 27 files changed, 137 insertions(+), 118 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index c6f07454d..583b06cd0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-named-parameter,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-modernize-pass-by-value,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-performance-unnecessary-value-param,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-readability-non-const-parameter,-misc-non-private-member-variables-in-classes,-bugprone-suspicious-string-compare,-clang-analyzer-*,-bugprone-signed-char-misuse,-readability-make-member-function-const,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-bugprone-suspicious-include,-modernize-replace-random-shuffle,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness' +Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-named-parameter,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-performance-unnecessary-value-param,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-readability-non-const-parameter,-misc-non-private-member-variables-in-classes,-bugprone-suspicious-string-compare,-clang-analyzer-*,-bugprone-signed-char-misuse,-readability-make-member-function-const,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-bugprone-suspicious-include,-modernize-replace-random-shuffle,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness' WarningsAsErrors: '*' CheckOptions: - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic diff --git a/gui/application.cpp b/gui/application.cpp index 858d4b666..3ae6aac46 100644 --- a/gui/application.cpp +++ b/gui/application.cpp @@ -18,9 +18,9 @@ #include "application.h" -Application::Application(const QString &name, const QString &path, - const QString ¶ms) - : mName(name) - , mPath(path) - , mParameters(params) +Application::Application(QString name, QString path, + QString params) + : mName(std::move(name)) + , mPath(std::move(path)) + , mParameters(std::move(params)) {} diff --git a/gui/application.h b/gui/application.h index ec28df985..d96ac45c7 100644 --- a/gui/application.h +++ b/gui/application.h @@ -43,7 +43,7 @@ class Application { public: Application() {} - Application(const QString &name, const QString &path, const QString ¶ms); + Application(QString name, QString path, QString params); /** * @brief Get application name. diff --git a/gui/codeeditorstyle.cpp b/gui/codeeditorstyle.cpp index 0a81945d9..3a448a9be 100644 --- a/gui/codeeditorstyle.cpp +++ b/gui/codeeditorstyle.cpp @@ -19,33 +19,42 @@ #include "codeeditorstyle.h" #include +#include CodeEditorStyle::CodeEditorStyle( - const QColor& CtrlFGColor, const QColor& CtrlBGColor, - const QColor& HiLiBGColor, - const QColor& LnNumFGColor, const QColor& LnNumBGColor, - const QColor& KeyWdFGColor, const QFont::Weight& KeyWdWeight, - const QColor& ClsFGColor, const QFont::Weight& ClsWeight, - const QColor& QteFGColor, const QFont::Weight& QteWeight, - const QColor& CmtFGColor, const QFont::Weight& CmtWeight, - const QColor& SymbFGColor, const QColor& SymbBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor CtrlFGColor, QColor CtrlBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor HiLiBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor LnNumFGColor, QColor LnNumBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor KeyWdFGColor, const QFont::Weight& KeyWdWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor ClsFGColor, const QFont::Weight& ClsWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor QteFGColor, const QFont::Weight& QteWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor CmtFGColor, const QFont::Weight& CmtWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor SymbFGColor, QColor SymbBGColor, const QFont::Weight& SymbWeight) : mSystemTheme(false), - widgetFGColor(CtrlFGColor), - widgetBGColor(CtrlBGColor), - highlightBGColor(HiLiBGColor), - lineNumFGColor(LnNumFGColor), - lineNumBGColor(LnNumBGColor), - keywordColor(KeyWdFGColor), + widgetFGColor(std::move(CtrlFGColor)), + widgetBGColor(std::move(CtrlBGColor)), + highlightBGColor(std::move(HiLiBGColor)), + lineNumFGColor(std::move(LnNumFGColor)), + lineNumBGColor(std::move(LnNumBGColor)), + keywordColor(std::move(KeyWdFGColor)), keywordWeight(KeyWdWeight), - classColor(ClsFGColor), + classColor(std::move(ClsFGColor)), classWeight(ClsWeight), - quoteColor(QteFGColor), + quoteColor(std::move(QteFGColor)), quoteWeight(QteWeight), - commentColor(CmtFGColor), + commentColor(std::move(CmtFGColor)), commentWeight(CmtWeight), - symbolFGColor(SymbFGColor), - symbolBGColor(SymbBGColor), + symbolFGColor(std::move(SymbFGColor)), + symbolBGColor(std::move(SymbBGColor)), symbolWeight(SymbWeight) {} diff --git a/gui/codeeditorstyle.h b/gui/codeeditorstyle.h index 20e906af7..c0f222fbc 100644 --- a/gui/codeeditorstyle.h +++ b/gui/codeeditorstyle.h @@ -50,14 +50,22 @@ class QSettings; class CodeEditorStyle { public: explicit CodeEditorStyle( - const QColor& CtrlFGColor, const QColor& CtrlBGColor, - const QColor& HiLiBGColor, - const QColor& LnNumFGColor, const QColor& LnNumBGColor, - const QColor& KeyWdFGColor, const QFont::Weight& KeyWdWeight, - const QColor& ClsFGColor, const QFont::Weight& ClsWeight, - const QColor& QteFGColor, const QFont::Weight& QteWeight, - const QColor& CmtFGColor, const QFont::Weight& CmtWeight, - const QColor& SymbFGColor, const QColor& SymbBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor CtrlFGColor, QColor CtrlBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor HiLiBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor LnNumFGColor, QColor LnNumBGColor, + // cppcheck-suppress naming-varname - TODO: fix this + QColor KeyWdFGColor, const QFont::Weight& KeyWdWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor ClsFGColor, const QFont::Weight& ClsWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor QteFGColor, const QFont::Weight& QteWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor CmtFGColor, const QFont::Weight& CmtWeight, + // cppcheck-suppress naming-varname - TODO: fix this + QColor SymbFGColor, QColor SymbBGColor, const QFont::Weight& SymbWeight); ~CodeEditorStyle() {} diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 23044f4a9..3eb49ca73 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -38,9 +38,9 @@ ProjectFile::ProjectFile(QObject *parent) : clear(); } -ProjectFile::ProjectFile(const QString &filename, QObject *parent) : +ProjectFile::ProjectFile(QString filename, QObject *parent) : QObject(parent), - mFilename(filename) + mFilename(std::move(filename)) { clear(); read(); diff --git a/gui/projectfile.h b/gui/projectfile.h index f4495334f..8951a4f94 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -46,7 +46,7 @@ class ProjectFile : public QObject { public: explicit ProjectFile(QObject *parent = nullptr); - explicit ProjectFile(const QString &filename, QObject *parent = nullptr); + explicit ProjectFile(QString filename, QObject *parent = nullptr); ~ProjectFile() override { if (this == mActiveProject) mActiveProject = nullptr; } diff --git a/gui/report.cpp b/gui/report.cpp index 9a2eb223b..926c24f4f 100644 --- a/gui/report.cpp +++ b/gui/report.cpp @@ -18,9 +18,9 @@ #include "report.h" -Report::Report(const QString &filename) : +Report::Report(QString filename) : QObject(), - mFilename(filename) + mFilename(std::move(filename)) {} Report::~Report() diff --git a/gui/report.h b/gui/report.h index 1ec336e51..5cea9be50 100644 --- a/gui/report.h +++ b/gui/report.h @@ -39,7 +39,7 @@ public: CSV, }; - explicit Report(const QString &filename); + explicit Report(QString filename); ~Report() override; /** diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index b864d6cd6..0c8a7a0d9 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -393,7 +393,7 @@ std::string CheckUnusedFunctions::analyzerInfo() const namespace { struct Location { Location() : lineNumber(0) {} - Location(const std::string &f, const int l) : fileName(f), lineNumber(l) {} + Location(std::string f, const int l) : fileName(std::move(f)), lineNumber(l) {} std::string fileName; int lineNumber; }; diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 3cf4a99a5..a41f0ea41 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -317,8 +317,8 @@ namespace clangimport { class AstNode { public: - AstNode(const std::string &nodeType, const std::string &ext, Data *data) - : nodeType(nodeType), mExtTokens(splitString(ext)), mData(data) + AstNode(std::string nodeType, const std::string &ext, Data *data) + : nodeType(std::move(nodeType)), mExtTokens(splitString(ext)), mData(data) {} std::string nodeType; std::vector children; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index d221c72e4..08227ba67 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -351,7 +351,7 @@ CppCheck::CppCheck(ErrorLogger &errorLogger, , mUseGlobalSuppressions(useGlobalSuppressions) , mTooManyConfigs(false) , mSimplify(true) - , mExecuteCommand(executeCommand) + , mExecuteCommand(std::move(executeCommand)) {} CppCheck::~CppCheck() diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index d8ed08ea2..c985d11c5 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -34,41 +34,18 @@ #include #include #include +#include #include -InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type type) : - token(tok), errorMessage(errorMsg), type(type) -{ - switch (type) { - case AST: - id = "internalAstError"; - break; - case SYNTAX: - id = "syntaxError"; - break; - case UNKNOWN_MACRO: - id = "unknownMacro"; - break; - case INTERNAL: - id = "cppcheckError"; - break; - case LIMIT: - id = "cppcheckLimit"; - break; - case INSTANTIATION: - id = "instantiationError"; - break; - } -} ErrorMessage::ErrorMessage() : incomplete(false), severity(Severity::none), cwe(0U), certainty(Certainty::normal), hash(0) {} -ErrorMessage::ErrorMessage(const std::list &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, Certainty::CertaintyLevel certainty) : - callStack(callStack), // locations for this error message - id(id), // set the message id - file0(file1), +ErrorMessage::ErrorMessage(std::list callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, Certainty::CertaintyLevel certainty) : + callStack(std::move(callStack)), // locations for this error message + id(std::move(id)), // set the message id + file0(std::move(file1)), incomplete(false), severity(severity), // severity for this error message cwe(0U), @@ -81,10 +58,10 @@ ErrorMessage::ErrorMessage(const std::list &callStack, const std:: -ErrorMessage::ErrorMessage(const std::list &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, Certainty::CertaintyLevel certainty) : - callStack(callStack), // locations for this error message - id(id), // set the message id - file0(file1), +ErrorMessage::ErrorMessage(std::list callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, const CWE &cwe, Certainty::CertaintyLevel certainty) : + callStack(std::move(callStack)), // locations for this error message + id(std::move(id)), // set the message id + file0(std::move(file1)), incomplete(false), severity(severity), // severity for this error message cwe(cwe.id), @@ -95,8 +72,8 @@ ErrorMessage::ErrorMessage(const std::list &callStack, const std:: setmsg(msg); } -ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, Certainty::CertaintyLevel certainty) - : id(id), incomplete(false), severity(severity), cwe(0U), certainty(certainty), hash(0) +ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, Certainty::CertaintyLevel certainty) + : id(std::move(id)), incomplete(false), severity(severity), cwe(0U), certainty(certainty), hash(0) { // Format callstack for (std::list::const_iterator it = callstack.begin(); it != callstack.end(); ++it) { @@ -114,8 +91,8 @@ ErrorMessage::ErrorMessage(const std::list& callstack, const Token } -ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, const CWE &cwe, Certainty::CertaintyLevel certainty) - : id(id), incomplete(false), severity(severity), cwe(cwe.id), certainty(certainty) +ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, const CWE &cwe, Certainty::CertaintyLevel certainty) + : id(std::move(id)), incomplete(false), severity(severity), cwe(cwe.id), certainty(certainty) { // Format callstack for (const Token *tok: callstack) { @@ -651,8 +628,8 @@ ErrorMessage::FileLocation::FileLocation(const Token* tok, const TokenList* toke : fileIndex(tok->fileIndex()), line(tok->linenr()), column(tok->column()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)) {} -ErrorMessage::FileLocation::FileLocation(const Token* tok, const std::string &info, const TokenList* tokenList) - : fileIndex(tok->fileIndex()), line(tok->linenr()), column(tok->column()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)), mInfo(info) +ErrorMessage::FileLocation::FileLocation(const Token* tok, std::string info, const TokenList* tokenList) + : fileIndex(tok->fileIndex()), line(tok->linenr()), column(tok->column()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)), mInfo(std::move(info)) {} std::string ErrorMessage::FileLocation::getfile(bool convert) const diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 702f10436..73f73071d 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -76,7 +76,7 @@ public: : fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file), mInfo(info) {} FileLocation(const Token* tok, const TokenList* tokenList); - FileLocation(const Token* tok, const std::string &info, const TokenList* tokenList); + FileLocation(const Token* tok, std::string info, const TokenList* tokenList); /** * Return the filename. @@ -120,28 +120,28 @@ public: std::string mInfo; }; - ErrorMessage(const std::list &callStack, - const std::string& file1, + ErrorMessage(std::list callStack, + std::string file1, Severity::SeverityType severity, const std::string &msg, - const std::string &id, Certainty::CertaintyLevel certainty); - ErrorMessage(const std::list &callStack, - const std::string& file1, + std::string id, Certainty::CertaintyLevel certainty); + ErrorMessage(std::list callStack, + std::string file1, Severity::SeverityType severity, const std::string &msg, - const std::string &id, + std::string id, const CWE &cwe, Certainty::CertaintyLevel certainty); ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, - const std::string& id, + std::string id, const std::string& msg, Certainty::CertaintyLevel certainty); ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, - const std::string& id, + std::string id, const std::string& msg, const CWE &cwe, Certainty::CertaintyLevel certainty); diff --git a/lib/errortypes.cpp b/lib/errortypes.cpp index a3dcea120..09f6b0f73 100644 --- a/lib/errortypes.cpp +++ b/lib/errortypes.cpp @@ -18,6 +18,31 @@ #include "errortypes.h" +InternalError::InternalError(const Token *tok, std::string errorMsg, Type type) : + token(tok), errorMessage(std::move(errorMsg)), type(type) +{ + switch (type) { + case AST: + id = "internalAstError"; + break; + case SYNTAX: + id = "syntaxError"; + break; + case UNKNOWN_MACRO: + id = "unknownMacro"; + break; + case INTERNAL: + id = "cppcheckError"; + break; + case LIMIT: + id = "cppcheckLimit"; + break; + case INSTANTIATION: + id = "instantiationError"; + break; + } +} + std::string Severity::toString(Severity::SeverityType severity) { switch (severity) { diff --git a/lib/errortypes.h b/lib/errortypes.h index d5512dd28..bcfd44b5b 100644 --- a/lib/errortypes.h +++ b/lib/errortypes.h @@ -34,7 +34,7 @@ class Token; /** @brief Simple container to be thrown when internal error is detected. */ struct InternalError { enum Type {AST, SYNTAX, UNKNOWN_MACRO, INTERNAL, LIMIT, INSTANTIATION}; - InternalError(const Token *tok, const std::string &errorMsg, Type type = INTERNAL); + InternalError(const Token *tok, std::string errorMsg, Type type = INTERNAL); const Token *token; std::string errorMessage; Type type; diff --git a/lib/importproject.cpp b/lib/importproject.cpp index f0a67693f..280ba6d09 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -528,7 +528,7 @@ namespace { }; struct ItemDefinitionGroup { - explicit ItemDefinitionGroup(const tinyxml2::XMLElement *idg, const std::string &includePaths) : additionalIncludePaths(includePaths) { + explicit ItemDefinitionGroup(const tinyxml2::XMLElement *idg, std::string includePaths) : additionalIncludePaths(std::move(includePaths)) { const char *condAttr = idg->Attribute("Condition"); if (condAttr) condition = condAttr; diff --git a/lib/pathmatch.cpp b/lib/pathmatch.cpp index 4c56db8f6..2131f4a70 100644 --- a/lib/pathmatch.cpp +++ b/lib/pathmatch.cpp @@ -23,8 +23,8 @@ #include -PathMatch::PathMatch(const std::vector &excludedPaths, bool caseSensitive) - : mExcludedPaths(excludedPaths), mCaseSensitive(caseSensitive) +PathMatch::PathMatch(std::vector excludedPaths, bool caseSensitive) + : mExcludedPaths(std::move(excludedPaths)), mCaseSensitive(caseSensitive) { if (!mCaseSensitive) for (std::string& excludedPath : mExcludedPaths) diff --git a/lib/pathmatch.h b/lib/pathmatch.h index 95ad3e083..7c8df1edc 100644 --- a/lib/pathmatch.h +++ b/lib/pathmatch.h @@ -39,7 +39,7 @@ public: * @param caseSensitive Match the case of the characters when * matching paths? */ - explicit PathMatch(const std::vector &excludedPaths, bool caseSensitive = true); + explicit PathMatch(std::vector excludedPaths, bool caseSensitive = true); /** * @brief Match path against list of masks. diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index f9c8402aa..96aadd796 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -56,8 +56,8 @@ static std::string trim(const std::string& s) return s.substr(beg, end - beg + 1); } -Directive::Directive(const std::string &_file, const int _linenr, const std::string &_str) : - file(_file), +Directive::Directive(std::string _file, const int _linenr, const std::string &_str) : + file(std::move(_file)), linenr(_linenr), str(trim(_str)) {} @@ -78,7 +78,7 @@ Preprocessor::~Preprocessor() namespace { struct BadInlineSuppression { - BadInlineSuppression(const simplecpp::Location &l, const std::string &msg) : location(l), errmsg(msg) {} + BadInlineSuppression(const simplecpp::Location &l, std::string msg) : location(l), errmsg(std::move(msg)) {} simplecpp::Location location; std::string errmsg; }; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 48ce2cb55..26a436415 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -56,7 +56,7 @@ public: std::string str; /** record a directive (possibly filtering src) */ - Directive(const std::string &_file, const int _linenr, const std::string &_str); + Directive(std::string _file, const int _linenr, const std::string &_str); }; /// @addtogroup Core diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 4d38c4cfa..37653c162 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -74,7 +74,7 @@ namespace { class FindName { public: - explicit FindName(const std::string &name) : mName(name) {} + explicit FindName(std::string name) : mName(std::move(name)) {} bool operator()(const TemplateSimplifier::TokenAndName &tokenAndName) const { return tokenAndName.name() == mName; } @@ -84,7 +84,7 @@ namespace { class FindFullName { public: - explicit FindFullName(const std::string &fullName) : mFullName(fullName) {} + explicit FindFullName(std::string fullName) : mFullName(std::move(fullName)) {} bool operator()(const TemplateSimplifier::TokenAndName &tokenAndName) const { return tokenAndName.fullName() == mFullName; } @@ -93,8 +93,8 @@ namespace { }; } -TemplateSimplifier::TokenAndName::TokenAndName(Token *token, const std::string &scope) : - mToken(token), mScope(scope), mName(mToken ? mToken->str() : ""), +TemplateSimplifier::TokenAndName::TokenAndName(Token *token, std::string scope) : + mToken(token), mScope(std::move(scope)), mName(mToken ? mToken->str() : ""), mFullName(mScope.empty() ? mName : (mScope + " :: " + mName)), mNameToken(nullptr), mParamEnd(nullptr), mFlags(0) { @@ -109,8 +109,8 @@ TemplateSimplifier::TokenAndName::TokenAndName(Token *token, const std::string & } } -TemplateSimplifier::TokenAndName::TokenAndName(Token *token, const std::string &scope, const Token *nameToken, const Token *paramEnd) : - mToken(token), mScope(scope), mName(nameToken->str()), +TemplateSimplifier::TokenAndName::TokenAndName(Token *token, std::string scope, const Token *nameToken, const Token *paramEnd) : + mToken(token), mScope(std::move(scope)), mName(nameToken->str()), mFullName(mScope.empty() ? mName : (mScope + " :: " + mName)), mNameToken(nameToken), mParamEnd(paramEnd), mFlags(0) { @@ -1588,7 +1588,7 @@ void TemplateSimplifier::expandTemplate( const bool isSpecialization = templateDeclaration.isSpecialization(); const bool isVariable = templateDeclaration.isVariable(); struct newInstantiation { - newInstantiation(Token *t, const std::string &s) : token(t), scope(s) {} + newInstantiation(Token *t, std::string s) : token(t), scope(std::move(s)) {} Token *token; std::string scope; }; diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 87f15b197..68e4693be 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -138,7 +138,7 @@ public: * \param token template instantiation name token "name<...>" * \param scope full qualification of template(scope) */ - TokenAndName(Token *token, const std::string &scope); + TokenAndName(Token *token, std::string scope); /** * Constructor used for declarations. * \param token template declaration token "template < ... >" @@ -146,7 +146,7 @@ public: * \param nameToken template name token "template < ... > class name" * \param paramEnd template parameter end token ">" */ - TokenAndName(Token *token, const std::string &scope, const Token *nameToken, const Token *paramEnd); + TokenAndName(Token *token, std::string scope, const Token *nameToken, const Token *paramEnd); TokenAndName(const TokenAndName& other); ~TokenAndName(); diff --git a/lib/timer.cpp b/lib/timer.cpp index a403d3a14..fd11f556f 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -71,8 +71,8 @@ void TimerResults::addResults(const std::string& str, std::clock_t clocks) mResults[str].mNumberOfResults++; } -Timer::Timer(const std::string& str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults) - : mStr(str) +Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults) + : mStr(std::move(str)) , mTimerResults(timerResults) , mStart(0) , mShowTimeMode(showtimeMode) diff --git a/lib/timer.h b/lib/timer.h index 9b00e833e..1395d131e 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -67,7 +67,7 @@ private: class CPPCHECKLIB Timer { public: - Timer(const std::string& str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults = nullptr); + Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults = nullptr); ~Timer(); Timer(const Timer&) = delete; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7f1c6baac..2a37fb9dc 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1835,8 +1835,8 @@ namespace { struct ScopeInfo3 { enum Type { Global, Namespace, Record, MemberFunction, Other }; ScopeInfo3() : parent(nullptr), type(Global), bodyStart(nullptr), bodyEnd(nullptr) {} - ScopeInfo3(ScopeInfo3 *parent_, Type type_, const std::string &name_, const Token *bodyStart_, const Token *bodyEnd_) - : parent(parent_), type(type_), name(name_), bodyStart(bodyStart_), bodyEnd(bodyEnd_) { + ScopeInfo3(ScopeInfo3 *parent_, Type type_, std::string name_, const Token *bodyStart_, const Token *bodyEnd_) + : parent(parent_), type(type_), name(std::move(name_)), bodyStart(bodyStart_), bodyEnd(bodyEnd_) { if (name.empty()) return; fullName = name; @@ -4182,7 +4182,7 @@ void Tokenizer::setVarIdPass1() namespace { struct Member { - Member(const std::list &s, const std::list &ns, Token *t) : usingnamespaces(ns), scope(s), tok(t) {} + Member(std::list s, std::list ns, Token *t) : usingnamespaces(std::move(ns)), scope(std::move(s)), tok(t) {} std::list usingnamespaces; std::list scope; Token *tok; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 589fd4239..1ab594a2e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2880,7 +2880,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer { SingleValueFlowAnalyzer() : ValueFlowAnalyzer() {} - SingleValueFlowAnalyzer(const ValueFlow::Value& v, const TokenList* t) : ValueFlowAnalyzer(t), value(v) {} + SingleValueFlowAnalyzer(ValueFlow::Value v, const TokenList* t) : ValueFlowAnalyzer(t), value(std::move(v)) {} const std::unordered_map& getVars() const { return varids; @@ -3798,11 +3798,11 @@ struct LifetimeStore { {} LifetimeStore(const Token* argtok, - const std::string& message, + std::string message, ValueFlow::Value::LifetimeKind type = ValueFlow::Value::LifetimeKind::Object, bool inconclusive = false) : argtok(argtok), - message(message), + message(std::move(message)), type(type), errorPath(), inconclusive(inconclusive),