fixed some clang-tidy warnings (#4435)

This commit is contained in:
Oliver Stöneberg 2022-09-08 20:01:41 +02:00 committed by GitHub
parent 7c986fbef1
commit dbc05da356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 54 additions and 54 deletions

View File

@ -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: '*' WarningsAsErrors: '*'
CheckOptions: CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic

View File

@ -82,14 +82,14 @@ public:
report(msg, MessageType::REPORT_INFO); report(msg, MessageType::REPORT_INFO);
} }
void writeEnd(const std::string& str) { void writeEnd(const std::string& str) const {
writeToPipe(CHILD_END, str); writeToPipe(CHILD_END, str);
} }
private: private:
enum class MessageType {REPORT_ERROR, REPORT_INFO}; enum class MessageType {REPORT_ERROR, REPORT_INFO};
void report(const ErrorMessage &msg, MessageType msgType) { void report(const ErrorMessage &msg, MessageType msgType) const {
PipeSignal pipeSignal; PipeSignal pipeSignal;
switch (msgType) { switch (msgType) {
case MessageType::REPORT_ERROR: case MessageType::REPORT_ERROR:
@ -103,7 +103,7 @@ private:
writeToPipe(pipeSignal, msg.serialize()); 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<unsigned int>(data.length() + 1); unsigned int len = static_cast<unsigned int>(data.length() + 1);
char *out = new char[len + 1 + sizeof(len)]; char *out = new char[len + 1 + sizeof(len)];

View File

@ -320,7 +320,7 @@ private:
void formatAndSetTitle(const QString &text = QString()); void formatAndSetTitle(const QString &text = QString());
/** @brief Show help contents */ /** @brief Show help contents */
void openOnlineHelp(); static void openOnlineHelp();
/** /**
* @brief Enable or disable project file actions. * @brief Enable or disable project file actions.

View File

@ -415,9 +415,9 @@ protected:
*/ */
void readImportProject(QXmlStreamReader &reader); 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. * @brief Read list of include directories from XML.
@ -473,7 +473,7 @@ protected:
* @param reader XML stream reader * @param reader XML stream reader
* @param elementname elementname for each string * @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 * @brief Write string list

View File

@ -316,7 +316,7 @@ protected:
int getSuppressionIndex(const QString &shortText) const; int getSuppressionIndex(const QString &shortText) const;
private: private:
QStringList getProjectConfigs(const QString &fileName); static QStringList getProjectConfigs(const QString &fileName);
Ui::ProjectFile *mUI; Ui::ProjectFile *mUI;

View File

@ -1156,7 +1156,7 @@ QString ResultsTree::getFilePath(QStandardItem *target, bool fullPath)
return QString(); return QString();
} }
QString ResultsTree::severityToIcon(Severity::SeverityType severity) const QString ResultsTree::severityToIcon(Severity::SeverityType severity)
{ {
switch (severity) { switch (severity) {
case Severity::error: case Severity::error:

View File

@ -329,7 +329,7 @@ protected:
* *
* @param severity Severity * @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* * @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 target The error tree item containing the filename/full path
* @param fullPath Whether or not to retrieve the full path or only the filename. * @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) * @brief Context menu event (user right clicked on the tree)

View File

@ -42,8 +42,8 @@ private slots:
void containerValid(); void containerValid();
private: private:
void loadCfgFile(QString filename, CppcheckLibraryData &data, QString &res, bool removeFile = false); static void loadCfgFile(QString filename, CppcheckLibraryData &data, QString &res, bool removeFile = false);
void saveCfgFile(QString filename, CppcheckLibraryData &data); static void saveCfgFile(QString filename, CppcheckLibraryData &data);
CppcheckLibraryData libraryData; CppcheckLibraryData libraryData;
CppcheckLibraryData fileLibraryData; CppcheckLibraryData fileLibraryData;

View File

@ -24,7 +24,7 @@
#include <QString> #include <QString>
#include <QTest> #include <QTest>
void TestFileList::addFile() void TestFileList::addFile() const
{ {
// Accepted extensions: *.cpp, *.cxx, *.cc, *.c, *.c++, *.txx, *.tpp, *.ipp, *.ixx" // Accepted extensions: *.cpp, *.cxx, *.cc, *.c, *.c++, *.txx, *.tpp, *.ipp, *.ixx"
FileList list; FileList list;
@ -41,7 +41,7 @@ void TestFileList::addFile()
QCOMPARE(files.size(), 9); QCOMPARE(files.size(), 9);
} }
void TestFileList::addPathList() void TestFileList::addPathList() const
{ {
// Accepted extensions: *.cpp, *.cxx, *.cc, *.c, *.c++, *.txx, *.tpp, *.ipp, *.ixx" // Accepted extensions: *.cpp, *.cxx, *.cc, *.c, *.c++, *.txx, *.tpp, *.ipp, *.ixx"
QStringList paths; QStringList paths;
@ -60,7 +60,7 @@ void TestFileList::addPathList()
QCOMPARE(files.size(), 9); QCOMPARE(files.size(), 9);
} }
void TestFileList::addFile_notexist() void TestFileList::addFile_notexist() const
{ {
FileList list; FileList list;
list.addFile(QString(SRCDIR) + "/../data/files/bar1.cpp"); list.addFile(QString(SRCDIR) + "/../data/files/bar1.cpp");
@ -68,7 +68,7 @@ void TestFileList::addFile_notexist()
QCOMPARE(files.size(), 0); QCOMPARE(files.size(), 0);
} }
void TestFileList::addFile_unknown() void TestFileList::addFile_unknown() const
{ {
FileList list; FileList list;
list.addFile(QString(SRCDIR) + "/../data/files/bar1"); list.addFile(QString(SRCDIR) + "/../data/files/bar1");
@ -77,7 +77,7 @@ void TestFileList::addFile_unknown()
QCOMPARE(files.size(), 0); QCOMPARE(files.size(), 0);
} }
void TestFileList::addDirectory() void TestFileList::addDirectory() const
{ {
FileList list; FileList list;
list.addDirectory(QString(SRCDIR) + "/../data/files"); list.addDirectory(QString(SRCDIR) + "/../data/files");
@ -85,7 +85,7 @@ void TestFileList::addDirectory()
QCOMPARE(files.size(), 7); QCOMPARE(files.size(), 7);
} }
void TestFileList::addDirectory_recursive() void TestFileList::addDirectory_recursive() const
{ {
FileList list; FileList list;
list.addDirectory(QString(SRCDIR) + "/../data/files", true); list.addDirectory(QString(SRCDIR) + "/../data/files", true);
@ -98,7 +98,7 @@ void TestFileList::addDirectory_recursive()
QVERIFY(files.contains(base + "/dir2/foo1.cpp")); QVERIFY(files.contains(base + "/dir2/foo1.cpp"));
} }
void TestFileList::filterFiles() void TestFileList::filterFiles() const
{ {
FileList list; FileList list;
QStringList filters; QStringList filters;
@ -121,7 +121,7 @@ void TestFileList::filterFiles()
QVERIFY(!files.contains(base + "/foo3.cpp")); QVERIFY(!files.contains(base + "/foo3.cpp"));
} }
void TestFileList::filterFiles2() void TestFileList::filterFiles2() const
{ {
FileList list; FileList list;
QStringList filters; QStringList filters;
@ -136,7 +136,7 @@ void TestFileList::filterFiles2()
QVERIFY(!files.contains(base + "/foo3.cpp")); QVERIFY(!files.contains(base + "/foo3.cpp"));
} }
void TestFileList::filterFiles3() void TestFileList::filterFiles3() const
{ {
FileList list; FileList list;
QStringList filters; QStringList filters;
@ -153,7 +153,7 @@ void TestFileList::filterFiles3()
QVERIFY(!files.contains(base + "/dir2/foo1.cpp")); QVERIFY(!files.contains(base + "/dir2/foo1.cpp"));
} }
void TestFileList::filterFiles4() void TestFileList::filterFiles4() const
{ {
FileList list; FileList list;
QStringList filters; QStringList filters;

View File

@ -22,14 +22,14 @@ class TestFileList : public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:
void addFile(); void addFile() const;
void addPathList(); void addPathList() const;
void addFile_notexist(); void addFile_notexist() const;
void addFile_unknown(); void addFile_unknown() const;
void addDirectory(); void addDirectory() const;
void addDirectory_recursive(); void addDirectory_recursive() const;
void filterFiles(); void filterFiles() const;
void filterFiles2(); void filterFiles2() const;
void filterFiles3(); void filterFiles3() const;
void filterFiles4(); void filterFiles4() const;
}; };

View File

@ -37,14 +37,14 @@ bool ImportProject::sourceFileExists(const std::string & /*file*/) {
return true; return true;
} }
void TestProjectFile::loadInexisting() void TestProjectFile::loadInexisting() const
{ {
const QString filepath(QString(SRCDIR) + "/../data/projectfiles/foo.cppcheck"); const QString filepath(QString(SRCDIR) + "/../data/projectfiles/foo.cppcheck");
ProjectFile pfile(filepath); ProjectFile pfile(filepath);
QCOMPARE(pfile.read(), false); QCOMPARE(pfile.read(), false);
} }
void TestProjectFile::loadSimple() void TestProjectFile::loadSimple() const
{ {
const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple.cppcheck"); const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple.cppcheck");
ProjectFile pfile(filepath); ProjectFile pfile(filepath);
@ -67,7 +67,7 @@ void TestProjectFile::loadSimple()
} }
// Test that project file with old 'ignore' element works // 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"); const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_ignore.cppcheck");
ProjectFile pfile(filepath); ProjectFile pfile(filepath);
@ -89,7 +89,7 @@ void TestProjectFile::loadSimpleWithIgnore()
QCOMPARE(defines[0], QString("FOO")); QCOMPARE(defines[0], QString("FOO"));
} }
void TestProjectFile::loadSimpleNoroot() void TestProjectFile::loadSimpleNoroot() const
{ {
const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_noroot.cppcheck"); const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_noroot.cppcheck");
ProjectFile pfile(filepath); ProjectFile pfile(filepath);

View File

@ -22,8 +22,8 @@ class TestProjectFile : public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:
void loadInexisting(); void loadInexisting() const;
void loadSimple(); void loadSimple() const;
void loadSimpleWithIgnore(); void loadSimpleWithIgnore() const;
void loadSimpleNoroot(); void loadSimpleNoroot() const;
}; };

View File

@ -31,7 +31,7 @@ static const QStringList getTranslationNames(const TranslationHandler& handler)
return names; return names;
} }
void TestTranslationHandler::construct() void TestTranslationHandler::construct() const
{ {
TranslationHandler handler; TranslationHandler handler;
QCOMPARE(getTranslationNames(handler).size(), 13); // 12 translations + english QCOMPARE(getTranslationNames(handler).size(), 13); // 12 translations + english

View File

@ -22,5 +22,5 @@ class TestTranslationHandler : public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:
void construct(); void construct() const;
}; };

View File

@ -23,7 +23,7 @@
#include <QtTest> #include <QtTest>
void TestXmlReportV2::readXml() void TestXmlReportV2::readXml() const
{ {
const QString filepath(QString(SRCDIR) + "/../data/xmlfiles/xmlreport_v2.xml"); const QString filepath(QString(SRCDIR) + "/../data/xmlfiles/xmlreport_v2.xml");
XmlReportV2 report(filepath); XmlReportV2 report(filepath);

View File

@ -22,5 +22,5 @@ class TestXmlReportV2 : public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:
void readXml(); void readXml() const;
}; };

View File

@ -2893,8 +2893,8 @@ void CheckClass::overrideError(const Function *funcInBase, const Function *funcI
ErrorPath errorPath; ErrorPath errorPath;
if (funcInBase && funcInDerived) { if (funcInBase && funcInDerived) {
errorPath.push_back(ErrorPathItem(funcInBase->tokenDef, "Virtual " + funcType + " in base class")); errorPath.emplace_back(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(funcInDerived->tokenDef, char(std::toupper(funcType[0])) + funcType.substr(1) + " in derived class");
} }
reportError(errorPath, Severity::style, "missingOverride", reportError(errorPath, Severity::style, "missingOverride",

View File

@ -208,7 +208,7 @@ namespace clangimport {
Decl(Token *def, Variable *var) : def(def), enumerator(nullptr), function(nullptr), scope(nullptr), var(var) {} 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, 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) {} 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) if (enumerator)
tok->enumerator(enumerator); tok->enumerator(enumerator);
if (function) if (function)

View File

@ -333,7 +333,7 @@ struct ForwardTraversal {
return false; return false;
} }
bool isEscapeScope(const Token* endBlock, bool& unknown) { bool isEscapeScope(const Token* endBlock, bool& unknown) const {
const Token* ftok = nullptr; const Token* ftok = nullptr;
bool r = isReturnScope(endBlock, &settings->library, &ftok); bool r = isReturnScope(endBlock, &settings->library, &ftok);
if (!r && ftok) if (!r && ftok)
@ -389,7 +389,7 @@ struct ForwardTraversal {
return bail; 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) if (!condTok)
return true; return true;
if (Token::simpleMatch(condTok, ":")) if (Token::simpleMatch(condTok, ":"))

View File

@ -4407,7 +4407,7 @@ struct Lambda {
std::unordered_map<const Variable*, std::pair<const Token*, LifetimeCapture>> explicitCaptures; std::unordered_map<const Variable*, std::pair<const Token*, LifetimeCapture>> explicitCaptures;
LifetimeCapture implicitCapture; LifetimeCapture implicitCapture;
std::vector<const Token*> getCaptures() { std::vector<const Token*> getCaptures() const {
return getArguments(capture); return getArguments(capture);
} }

View File

@ -534,13 +534,13 @@ private:
return values.size() == 1U && !values.front().isTokValue() ? values.front() : ValueFlow::Value(); return values.size() == 1U && !values.front().isTokValue() ? values.front() : ValueFlow::Value();
} }
std::list<ValueFlow::Value> removeSymbolic(std::list<ValueFlow::Value> values) static std::list<ValueFlow::Value> removeSymbolic(std::list<ValueFlow::Value> values)
{ {
values.remove_if(std::mem_fn(&ValueFlow::Value::isSymbolicValue)); values.remove_if(std::mem_fn(&ValueFlow::Value::isSymbolicValue));
return values; return values;
} }
std::list<ValueFlow::Value> removeImpossible(std::list<ValueFlow::Value> values) static std::list<ValueFlow::Value> removeImpossible(std::list<ValueFlow::Value> values)
{ {
values.remove_if(std::mem_fn(&ValueFlow::Value::isImpossible)); values.remove_if(std::mem_fn(&ValueFlow::Value::isImpossible));
return values; return values;