diff --git a/.clang-tidy b/.clang-tidy index 583b06cd0..13451e0d6 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,-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,-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/cli/processexecutor.cpp b/cli/processexecutor.cpp index 1448a0bc3..2719513a1 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -82,14 +82,14 @@ public: report(msg, MessageType::REPORT_INFO); } - void writeEnd(const std::string& str) { + void writeEnd(const std::string& str) const { writeToPipe(CHILD_END, str); } private: enum class MessageType {REPORT_ERROR, REPORT_INFO}; - void report(const ErrorMessage &msg, MessageType msgType) { + void report(const ErrorMessage &msg, MessageType msgType) const { PipeSignal pipeSignal; switch (msgType) { case MessageType::REPORT_ERROR: @@ -103,7 +103,7 @@ private: writeToPipe(pipeSignal, msg.serialize()); } - void writeToPipe(PipeSignal type, const std::string &data) + void writeToPipe(PipeSignal type, const std::string &data) const { unsigned int len = static_cast(data.length() + 1); char *out = new char[len + 1 + sizeof(len)]; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 564674079..617c8187a 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -320,7 +320,7 @@ private: void formatAndSetTitle(const QString &text = QString()); /** @brief Show help contents */ - void openOnlineHelp(); + static void openOnlineHelp(); /** * @brief Enable or disable project file actions. diff --git a/gui/projectfile.h b/gui/projectfile.h index 92abca02a..0e60ddbb9 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -415,9 +415,9 @@ protected: */ void readImportProject(QXmlStreamReader &reader); - bool readBool(QXmlStreamReader &reader); + static bool readBool(QXmlStreamReader &reader); - int readInt(QXmlStreamReader &reader, int defaultValue); + static int readInt(QXmlStreamReader &reader, int defaultValue); /** * @brief Read list of include directories from XML. @@ -473,7 +473,7 @@ protected: * @param reader XML stream reader * @param elementname elementname for each string */ - void readStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[]); + static void readStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[]); /** * @brief Write string list diff --git a/gui/projectfiledialog.h b/gui/projectfiledialog.h index 18c8deece..d7f803e8a 100644 --- a/gui/projectfiledialog.h +++ b/gui/projectfiledialog.h @@ -316,7 +316,7 @@ protected: int getSuppressionIndex(const QString &shortText) const; private: - QStringList getProjectConfigs(const QString &fileName); + static QStringList getProjectConfigs(const QString &fileName); Ui::ProjectFile *mUI; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index b93e5685e..7eada6f4c 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -1156,7 +1156,7 @@ QString ResultsTree::getFilePath(QStandardItem *target, bool fullPath) return QString(); } -QString ResultsTree::severityToIcon(Severity::SeverityType severity) const +QString ResultsTree::severityToIcon(Severity::SeverityType severity) { switch (severity) { case Severity::error: diff --git a/gui/resultstree.h b/gui/resultstree.h index c72c435ab..6f0c6800e 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -329,7 +329,7 @@ protected: * * @param severity Severity */ - QString severityToIcon(Severity::SeverityType severity) const; + static QString severityToIcon(Severity::SeverityType severity); /** * @brief Helper function to open an error within target with application* @@ -354,7 +354,7 @@ protected: * @param target The error tree item containing the filename/full path * @param fullPath Whether or not to retrieve the full path or only the filename. */ - QString getFilePath(QStandardItem *target, bool fullPath); + static QString getFilePath(QStandardItem *target, bool fullPath); /** * @brief Context menu event (user right clicked on the tree) diff --git a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h index 12a9efd5a..1073fb7ac 100644 --- a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h +++ b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h @@ -42,8 +42,8 @@ private slots: void containerValid(); private: - void loadCfgFile(QString filename, CppcheckLibraryData &data, QString &res, bool removeFile = false); - void saveCfgFile(QString filename, CppcheckLibraryData &data); + static void loadCfgFile(QString filename, CppcheckLibraryData &data, QString &res, bool removeFile = false); + static void saveCfgFile(QString filename, CppcheckLibraryData &data); CppcheckLibraryData libraryData; CppcheckLibraryData fileLibraryData; diff --git a/gui/test/filelist/testfilelist.cpp b/gui/test/filelist/testfilelist.cpp index c0f25fa22..c8d48efa1 100644 --- a/gui/test/filelist/testfilelist.cpp +++ b/gui/test/filelist/testfilelist.cpp @@ -24,7 +24,7 @@ #include #include -void TestFileList::addFile() +void TestFileList::addFile() const { // Accepted extensions: *.cpp, *.cxx, *.cc, *.c, *.c++, *.txx, *.tpp, *.ipp, *.ixx" FileList list; @@ -41,7 +41,7 @@ void TestFileList::addFile() QCOMPARE(files.size(), 9); } -void TestFileList::addPathList() +void TestFileList::addPathList() const { // Accepted extensions: *.cpp, *.cxx, *.cc, *.c, *.c++, *.txx, *.tpp, *.ipp, *.ixx" QStringList paths; @@ -60,7 +60,7 @@ void TestFileList::addPathList() QCOMPARE(files.size(), 9); } -void TestFileList::addFile_notexist() +void TestFileList::addFile_notexist() const { FileList list; list.addFile(QString(SRCDIR) + "/../data/files/bar1.cpp"); @@ -68,7 +68,7 @@ void TestFileList::addFile_notexist() QCOMPARE(files.size(), 0); } -void TestFileList::addFile_unknown() +void TestFileList::addFile_unknown() const { FileList list; list.addFile(QString(SRCDIR) + "/../data/files/bar1"); @@ -77,7 +77,7 @@ void TestFileList::addFile_unknown() QCOMPARE(files.size(), 0); } -void TestFileList::addDirectory() +void TestFileList::addDirectory() const { FileList list; list.addDirectory(QString(SRCDIR) + "/../data/files"); @@ -85,7 +85,7 @@ void TestFileList::addDirectory() QCOMPARE(files.size(), 7); } -void TestFileList::addDirectory_recursive() +void TestFileList::addDirectory_recursive() const { FileList list; list.addDirectory(QString(SRCDIR) + "/../data/files", true); @@ -98,7 +98,7 @@ void TestFileList::addDirectory_recursive() QVERIFY(files.contains(base + "/dir2/foo1.cpp")); } -void TestFileList::filterFiles() +void TestFileList::filterFiles() const { FileList list; QStringList filters; @@ -121,7 +121,7 @@ void TestFileList::filterFiles() QVERIFY(!files.contains(base + "/foo3.cpp")); } -void TestFileList::filterFiles2() +void TestFileList::filterFiles2() const { FileList list; QStringList filters; @@ -136,7 +136,7 @@ void TestFileList::filterFiles2() QVERIFY(!files.contains(base + "/foo3.cpp")); } -void TestFileList::filterFiles3() +void TestFileList::filterFiles3() const { FileList list; QStringList filters; @@ -153,7 +153,7 @@ void TestFileList::filterFiles3() QVERIFY(!files.contains(base + "/dir2/foo1.cpp")); } -void TestFileList::filterFiles4() +void TestFileList::filterFiles4() const { FileList list; QStringList filters; diff --git a/gui/test/filelist/testfilelist.h b/gui/test/filelist/testfilelist.h index 61e579d0b..5fbc420ea 100644 --- a/gui/test/filelist/testfilelist.h +++ b/gui/test/filelist/testfilelist.h @@ -22,14 +22,14 @@ class TestFileList : public QObject { Q_OBJECT private slots: - void addFile(); - void addPathList(); - void addFile_notexist(); - void addFile_unknown(); - void addDirectory(); - void addDirectory_recursive(); - void filterFiles(); - void filterFiles2(); - void filterFiles3(); - void filterFiles4(); + void addFile() const; + void addPathList() const; + void addFile_notexist() const; + void addFile_unknown() const; + void addDirectory() const; + void addDirectory_recursive() const; + void filterFiles() const; + void filterFiles2() const; + void filterFiles3() const; + void filterFiles4() const; }; diff --git a/gui/test/projectfile/testprojectfile.cpp b/gui/test/projectfile/testprojectfile.cpp index 52ce479c3..bcc1fc2d7 100644 --- a/gui/test/projectfile/testprojectfile.cpp +++ b/gui/test/projectfile/testprojectfile.cpp @@ -37,14 +37,14 @@ bool ImportProject::sourceFileExists(const std::string & /*file*/) { return true; } -void TestProjectFile::loadInexisting() +void TestProjectFile::loadInexisting() const { const QString filepath(QString(SRCDIR) + "/../data/projectfiles/foo.cppcheck"); ProjectFile pfile(filepath); QCOMPARE(pfile.read(), false); } -void TestProjectFile::loadSimple() +void TestProjectFile::loadSimple() const { const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple.cppcheck"); ProjectFile pfile(filepath); @@ -67,7 +67,7 @@ void TestProjectFile::loadSimple() } // Test that project file with old 'ignore' element works -void TestProjectFile::loadSimpleWithIgnore() +void TestProjectFile::loadSimpleWithIgnore() const { const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_ignore.cppcheck"); ProjectFile pfile(filepath); @@ -89,7 +89,7 @@ void TestProjectFile::loadSimpleWithIgnore() QCOMPARE(defines[0], QString("FOO")); } -void TestProjectFile::loadSimpleNoroot() +void TestProjectFile::loadSimpleNoroot() const { const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_noroot.cppcheck"); ProjectFile pfile(filepath); diff --git a/gui/test/projectfile/testprojectfile.h b/gui/test/projectfile/testprojectfile.h index ac01d5b54..762c893d7 100644 --- a/gui/test/projectfile/testprojectfile.h +++ b/gui/test/projectfile/testprojectfile.h @@ -22,8 +22,8 @@ class TestProjectFile : public QObject { Q_OBJECT private slots: - void loadInexisting(); - void loadSimple(); - void loadSimpleWithIgnore(); - void loadSimpleNoroot(); + void loadInexisting() const; + void loadSimple() const; + void loadSimpleWithIgnore() const; + void loadSimpleNoroot() const; }; diff --git a/gui/test/translationhandler/testtranslationhandler.cpp b/gui/test/translationhandler/testtranslationhandler.cpp index 1ded6c297..e726970f2 100644 --- a/gui/test/translationhandler/testtranslationhandler.cpp +++ b/gui/test/translationhandler/testtranslationhandler.cpp @@ -31,7 +31,7 @@ static const QStringList getTranslationNames(const TranslationHandler& handler) return names; } -void TestTranslationHandler::construct() +void TestTranslationHandler::construct() const { TranslationHandler handler; QCOMPARE(getTranslationNames(handler).size(), 13); // 12 translations + english diff --git a/gui/test/translationhandler/testtranslationhandler.h b/gui/test/translationhandler/testtranslationhandler.h index c18308b89..29f3e417f 100644 --- a/gui/test/translationhandler/testtranslationhandler.h +++ b/gui/test/translationhandler/testtranslationhandler.h @@ -22,5 +22,5 @@ class TestTranslationHandler : public QObject { Q_OBJECT private slots: - void construct(); + void construct() const; }; diff --git a/gui/test/xmlreportv2/testxmlreportv2.cpp b/gui/test/xmlreportv2/testxmlreportv2.cpp index 07496962d..90a273225 100644 --- a/gui/test/xmlreportv2/testxmlreportv2.cpp +++ b/gui/test/xmlreportv2/testxmlreportv2.cpp @@ -23,7 +23,7 @@ #include -void TestXmlReportV2::readXml() +void TestXmlReportV2::readXml() const { const QString filepath(QString(SRCDIR) + "/../data/xmlfiles/xmlreport_v2.xml"); XmlReportV2 report(filepath); diff --git a/gui/test/xmlreportv2/testxmlreportv2.h b/gui/test/xmlreportv2/testxmlreportv2.h index b78b50f4b..2afbe54fc 100644 --- a/gui/test/xmlreportv2/testxmlreportv2.h +++ b/gui/test/xmlreportv2/testxmlreportv2.h @@ -22,5 +22,5 @@ class TestXmlReportV2 : public QObject { Q_OBJECT private slots: - void readXml(); + void readXml() const; }; diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 178d0c0fd..d081afb12 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2893,8 +2893,8 @@ void CheckClass::overrideError(const Function *funcInBase, const Function *funcI ErrorPath errorPath; if (funcInBase && funcInDerived) { - errorPath.push_back(ErrorPathItem(funcInBase->tokenDef, "Virtual " + funcType + " in base class")); - errorPath.push_back(ErrorPathItem(funcInDerived->tokenDef, char(std::toupper(funcType[0])) + funcType.substr(1) + " in derived class")); + errorPath.emplace_back(funcInBase->tokenDef, "Virtual " + funcType + " in base class"); + errorPath.emplace_back(funcInDerived->tokenDef, char(std::toupper(funcType[0])) + funcType.substr(1) + " in derived class"); } reportError(errorPath, Severity::style, "missingOverride", diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 1462eed72..7ece09c63 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -208,7 +208,7 @@ namespace clangimport { Decl(Token *def, Variable *var) : def(def), enumerator(nullptr), function(nullptr), scope(nullptr), var(var) {} Decl(Token *def, Function *function) : def(def), enumerator(nullptr), function(function), scope(nullptr), var(nullptr) {} Decl(Token *def, Enumerator *enumerator) : def(def), enumerator(enumerator), function(nullptr), scope(nullptr), var(nullptr) {} - void ref(Token *tok) { + void ref(Token *tok) const { if (enumerator) tok->enumerator(enumerator); if (function) diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index 8a3bc6105..5435109c7 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -333,7 +333,7 @@ struct ForwardTraversal { return false; } - bool isEscapeScope(const Token* endBlock, bool& unknown) { + bool isEscapeScope(const Token* endBlock, bool& unknown) const { const Token* ftok = nullptr; bool r = isReturnScope(endBlock, &settings->library, &ftok); if (!r && ftok) @@ -389,7 +389,7 @@ struct ForwardTraversal { return bail; } - bool reentersLoop(Token* endBlock, const Token* condTok, const Token* stepTok) { + bool reentersLoop(Token* endBlock, const Token* condTok, const Token* stepTok) const { if (!condTok) return true; if (Token::simpleMatch(condTok, ":")) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 0a58ada5a..6f8712e88 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4407,7 +4407,7 @@ struct Lambda { std::unordered_map> explicitCaptures; LifetimeCapture implicitCapture; - std::vector getCaptures() { + std::vector getCaptures() const { return getArguments(capture); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 604033309..70ad741c8 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -534,13 +534,13 @@ private: return values.size() == 1U && !values.front().isTokValue() ? values.front() : ValueFlow::Value(); } - std::list removeSymbolic(std::list values) + static std::list removeSymbolic(std::list values) { values.remove_if(std::mem_fn(&ValueFlow::Value::isSymbolicValue)); return values; } - std::list removeImpossible(std::list values) + static std::list removeImpossible(std::list values) { values.remove_if(std::mem_fn(&ValueFlow::Value::isImpossible)); return values;