mitigated some clang-tidy warnings in headers (#4472)

* erroritem.h: avoid `performance-no-int-to-ptr` clang-tidy warning

* suppress `readability-inconsistent-declaration-parameter-name` clang-tidy warnings for Qt signals

* tokenlist.h: mitigated `readability-make-member-function-const` clang-tidy warnings

* fixed `modernize-use-override` clang-tidy warnings in headers

* fixed `modernize-pass-by-value` clang-tidy warnings in headers

* tokenize.cpp: avoid unnecessary copy
This commit is contained in:
Oliver Stöneberg 2022-09-16 18:59:15 +02:00 committed by GitHub
parent 339484d2a1
commit 897826006e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 47 additions and 19 deletions

View File

@ -39,7 +39,7 @@ class ProcessExecutor : public Executor {
public: public:
ProcessExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger); ProcessExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger);
ProcessExecutor(const ProcessExecutor &) = delete; ProcessExecutor(const ProcessExecutor &) = delete;
~ProcessExecutor(); ~ProcessExecutor() override;
void operator=(const ProcessExecutor &) = delete; void operator=(const ProcessExecutor &) = delete;
unsigned int check() override; unsigned int check() override;

View File

@ -41,7 +41,7 @@ class ThreadExecutor : public Executor {
public: public:
ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger); ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger);
ThreadExecutor(const ThreadExecutor &) = delete; ThreadExecutor(const ThreadExecutor &) = delete;
~ThreadExecutor(); ~ThreadExecutor() override;
void operator=(const ThreadExecutor &) = delete; void operator=(const ThreadExecutor &) = delete;
unsigned int check() override; unsigned int check() override;

View File

@ -95,6 +95,7 @@ signals:
*/ */
void done(); void done();
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void fileChecked(const QString &file); void fileChecked(const QString &file);
protected: protected:

View File

@ -40,6 +40,7 @@ public:
const QColor& getColor(); const QColor& getColor();
signals: signals:
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void colorChanged(const QColor& newColor); void colorChanged(const QColor& newColor);
public slots: public slots:
@ -61,6 +62,7 @@ public:
const QFont::Weight& getWeight(); const QFont::Weight& getWeight();
signals: signals:
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void weightChanged(const QFont::Weight& newWeight); void weightChanged(const QFont::Weight& newWeight);
public slots: public slots:

View File

@ -102,6 +102,7 @@ public:
static bool sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2); static bool sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
}; };
// NOLINTNEXTLINE(performance-no-int-to-ptr)
Q_DECLARE_METATYPE(ErrorItem) Q_DECLARE_METATYPE(ErrorItem)
/** /**

View File

@ -188,6 +188,7 @@ signals:
* *
* @param hidden true if there are some hidden results, or false if there are not * @param hidden true if there are some hidden results, or false if there are not
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void resultsHidden(bool hidden); void resultsHidden(bool hidden);
/** /**
@ -195,6 +196,7 @@ signals:
* *
* @param selectedItems list of selected files * @param selectedItems list of selected files
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void checkSelected(QStringList selectedItems); void checkSelected(QStringList selectedItems);
/** /**
@ -202,9 +204,11 @@ signals:
* *
* @param current Model index to specify new selected item. * @param current Model index to specify new selected item.
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void treeSelectionChanged(const QModelIndex &current); void treeSelectionChanged(const QModelIndex &current);
/** Suppress Ids */ /** Suppress Ids */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void suppressIds(QStringList ids); void suppressIds(QStringList ids);
public slots: public slots:

View File

@ -212,6 +212,7 @@ signals:
* *
* @param hidden true if there are some hidden results, or false if there are not * @param hidden true if there are some hidden results, or false if there are not
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void resultsHidden(bool hidden); void resultsHidden(bool hidden);
/** /**
@ -219,9 +220,11 @@ signals:
* *
* @param selectedFilesList list of selected files * @param selectedFilesList list of selected files
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void checkSelected(QStringList selectedFilesList); void checkSelected(QStringList selectedFilesList);
/** Suppress Ids */ /** Suppress Ids */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void suppressIds(QStringList ids); void suppressIds(QStringList ids);
/** /**
@ -231,6 +234,7 @@ signals:
* @param type Type of error to show/hide * @param type Type of error to show/hide
* @param show Should specified errors be shown (true) or hidden (false) * @param show Should specified errors be shown (true) or hidden (false)
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void showResults(ShowTypes::ShowType type, bool show); void showResults(ShowTypes::ShowType type, bool show);
/** /**
@ -239,6 +243,7 @@ signals:
* *
* @param show Should specified errors be shown (true) or hidden (false) * @param show Should specified errors be shown (true) or hidden (false)
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void showCppcheckResults(bool show); void showCppcheckResults(bool show);
/** /**
@ -247,6 +252,7 @@ signals:
* *
* @param show Should specified errors be shown (true) or hidden (false) * @param show Should specified errors be shown (true) or hidden (false)
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void showClangResults(bool show); void showClangResults(bool show);
/** /**

View File

@ -184,8 +184,10 @@ signals:
*/ */
void done(); void done();
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void log(const QString &msg); void log(const QString &msg);
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void debugError(const ErrorItem &item); void debugError(const ErrorItem &item);
public slots: public slots:

View File

@ -93,6 +93,7 @@ signals:
* @param value Current progress * @param value Current progress
* @param description Description of the current stage * @param description Description of the current stage
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void progress(int value, const QString& description); void progress(int value, const QString& description);
/** /**
@ -100,6 +101,7 @@ signals:
* *
* @param item Error data * @param item Error data
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void error(const ErrorItem &item); void error(const ErrorItem &item);
/** /**
@ -107,6 +109,7 @@ signals:
* *
* @param logline Log line * @param logline Log line
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void log(const QString &logline); void log(const QString &logline);
/** /**
@ -114,6 +117,7 @@ signals:
* *
* @param item Error data * @param item Error data
*/ */
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
void debugError(const ErrorItem &item); void debugError(const ErrorItem &item);
protected: protected:

View File

@ -26,6 +26,7 @@
#include <list> #include <list>
#include <string> #include <string>
#include <utility>
namespace tinyxml2 { namespace tinyxml2 {
class XMLElement; class XMLElement;
@ -61,8 +62,8 @@ public:
explicit Check(const std::string &aname); explicit Check(const std::string &aname);
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) Check(std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger), mName(aname) {} : mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger), mName(std::move(aname)) {}
virtual ~Check() { virtual ~Check() {
if (!mTokenizer) if (!mTokenizer)

View File

@ -31,6 +31,7 @@
#include <list> #include <list>
#include <map> #include <map>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
class Function; class Function;
@ -57,7 +58,7 @@ namespace CTU {
struct Location { struct Location {
Location() = default; Location() = default;
Location(const Tokenizer *tokenizer, const Token *tok); Location(const Tokenizer *tokenizer, const Token *tok);
Location(const std::string &fileName, nonneg int lineNumber, nonneg int column) : fileName(fileName), lineNumber(lineNumber), column(column) {} Location(std::string fileName, nonneg int lineNumber, nonneg int column) : fileName(std::move(fileName)), lineNumber(lineNumber), column(column) {}
std::string fileName; std::string fileName;
nonneg int lineNumber{}; nonneg int lineNumber{};
nonneg int column{}; nonneg int column{};
@ -65,7 +66,7 @@ namespace CTU {
struct UnsafeUsage { struct UnsafeUsage {
UnsafeUsage() = default; UnsafeUsage() = default;
UnsafeUsage(const std::string &myId, nonneg int myArgNr, const std::string &myArgumentName, const Location &location, MathLib::bigint value) : myId(myId), myArgNr(myArgNr), myArgumentName(myArgumentName), location(location), value(value) {} UnsafeUsage(std::string myId, nonneg int myArgNr, std::string myArgumentName, Location location, MathLib::bigint value) : myId(std::move(myId)), myArgNr(myArgNr), myArgumentName(std::move(myArgumentName)), location(std::move(location)), value(value) {}
std::string myId; std::string myId;
nonneg int myArgNr{}; nonneg int myArgNr{};
std::string myArgumentName; std::string myArgumentName;
@ -77,8 +78,8 @@ namespace CTU {
class CallBase { class CallBase {
public: public:
CallBase() = default; CallBase() = default;
CallBase(const std::string &callId, int callArgNr, const std::string &callFunctionName, const Location &loc) CallBase(std::string callId, int callArgNr, std::string callFunctionName, Location loc)
: callId(callId), callArgNr(callArgNr), callFunctionName(callFunctionName), location(loc) : callId(std::move(callId)), callArgNr(callArgNr), callFunctionName(std::move(callFunctionName)), location(std::move(loc))
{} {}
CallBase(const Tokenizer *tokenizer, const Token *callToken); CallBase(const Tokenizer *tokenizer, const Token *callToken);
virtual ~CallBase() {} virtual ~CallBase() {}
@ -107,9 +108,9 @@ namespace CTU {
public: public:
NestedCall() = default; NestedCall() = default;
NestedCall(const std::string &myId, nonneg int myArgNr, const std::string &callId, nonneg int callArgnr, const std::string &callFunctionName, const Location &location) NestedCall(std::string myId, nonneg int myArgNr, const std::string &callId, nonneg int callArgnr, const std::string &callFunctionName, const Location &location)
: CallBase(callId, callArgnr, callFunctionName, location), : CallBase(callId, callArgnr, callFunctionName, location),
myId(myId), myId(std::move(myId)),
myArgNr(myArgNr) {} myArgNr(myArgNr) {}
NestedCall(const Tokenizer *tokenizer, const Function *myFunction, const Token *callToken); NestedCall(const Tokenizer *tokenizer, const Function *myFunction, const Token *callToken);

View File

@ -30,6 +30,7 @@
#include <fstream> #include <fstream>
#include <list> #include <list>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
/** /**
@ -72,8 +73,8 @@ public:
FileLocation(const std::string &file, int line, unsigned int column) FileLocation(const std::string &file, int line, unsigned int column)
: fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file) {} : fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file) {}
FileLocation(const std::string &file, const std::string &info, int line, unsigned int column) FileLocation(const std::string &file, std::string info, int line, unsigned int column)
: fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file), mInfo(info) {} : fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file), mInfo(std::move(info)) {}
FileLocation(const Token* tok, const TokenList* tokenList); FileLocation(const Token* tok, const TokenList* tokenList);
FileLocation(const Token* tok, std::string info, const TokenList* tokenList); FileLocation(const Token* tok, std::string info, const TokenList* tokenList);

View File

@ -28,6 +28,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <utility>
class Token; class Token;
class Settings; class Settings;
@ -66,7 +67,7 @@ struct ProgramMemory {
ProgramMemory() = default; ProgramMemory() = default;
explicit ProgramMemory(const Map& values) : mValues(values) {} explicit ProgramMemory(Map values) : mValues(std::move(values)) {}
void setValue(const Token* expr, const ValueFlow::Value& value); void setValue(const Token* expr, const ValueFlow::Value& value);
const ValueFlow::Value* getValue(nonneg int exprid, bool impossible = false) const; const ValueFlow::Value* getValue(nonneg int exprid, bool impossible = false) const;

View File

@ -27,6 +27,7 @@
#include <istream> #include <istream>
#include <list> #include <list>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
/// @addtogroup Core /// @addtogroup Core
@ -57,7 +58,7 @@ public:
Suppression(const Suppression &other) { Suppression(const Suppression &other) {
*this = other; *this = other;
} }
Suppression(const std::string &id, const std::string &file, int line=NO_LINE) : errorId(id), fileName(file), lineNumber(line), hash(0), thisAndNextLine(false), matched(false), checked(false) {} Suppression(std::string id, std::string file, int line=NO_LINE) : errorId(std::move(id)), fileName(std::move(file)), lineNumber(line), hash(0), thisAndNextLine(false), matched(false), checked(false) {}
Suppression & operator=(const Suppression &other) { Suppression & operator=(const Suppression &other) {
errorId = other.errorId; errorId = other.errorId;

View File

@ -1304,7 +1304,7 @@ public:
containerTypeToken(nullptr), containerTypeToken(nullptr),
debugPath() debugPath()
{} {}
ValueType(enum Sign s, enum Type t, nonneg int p, nonneg int c, const std::string& otn) ValueType(enum Sign s, enum Type t, nonneg int p, nonneg int c, std::string otn)
: sign(s), : sign(s),
type(t), type(t),
bits(0), bits(0),
@ -1316,7 +1316,7 @@ public:
smartPointer(nullptr), smartPointer(nullptr),
container(nullptr), container(nullptr),
containerTypeToken(nullptr), containerTypeToken(nullptr),
originalTypeName(otn), originalTypeName(std::move(otn)),
debugPath() debugPath()
{} {}

View File

@ -59,7 +59,7 @@ struct TokensFrontBack {
}; };
struct ScopeInfo2 { struct ScopeInfo2 {
ScopeInfo2(const std::string &name_, const Token *bodyEnd_, const std::set<std::string> &usingNamespaces_ = std::set<std::string>()) : name(name_), bodyEnd(bodyEnd_), usingNamespaces(usingNamespaces_) {} ScopeInfo2(std::string name_, const Token *bodyEnd_, std::set<std::string> usingNamespaces_ = std::set<std::string>()) : name(std::move(name_)), bodyEnd(bodyEnd_), usingNamespaces(std::move(usingNamespaces_)) {}
std::string name; std::string name;
const Token * const bodyEnd; const Token * const bodyEnd;
std::set<std::string> usingNamespaces; std::set<std::string> usingNamespaces;

View File

@ -3348,7 +3348,7 @@ void Tokenizer::calculateScopes()
tok->scopeInfo(nullptr); tok->scopeInfo(nullptr);
std::string nextScopeNameAddition; std::string nextScopeNameAddition;
std::shared_ptr<ScopeInfo2> primaryScope = std::make_shared<ScopeInfo2>(emptyString, nullptr); std::shared_ptr<ScopeInfo2> primaryScope = std::make_shared<ScopeInfo2>("", nullptr);
list.front()->scopeInfo(primaryScope); list.front()->scopeInfo(primaryScope);
for (Token* tok = list.front(); tok; tok = tok->next()) { for (Token* tok = list.front(); tok; tok = tok->next()) {

View File

@ -116,6 +116,7 @@ public:
const Token *front() const { const Token *front() const {
return mTokensFrontBack.front; return mTokensFrontBack.front;
} }
// NOLINTNEXTLINE(readability-make-member-function-const) - do not allow usage of mutable pointer from const object
Token *front() { Token *front() {
return mTokensFrontBack.front; return mTokensFrontBack.front;
} }
@ -124,6 +125,7 @@ public:
const Token *back() const { const Token *back() const {
return mTokensFrontBack.back; return mTokensFrontBack.back;
} }
// NOLINTNEXTLINE(readability-make-member-function-const) - do not allow usage of mutable pointer from const object
Token *back() { Token *back() {
return mTokensFrontBack.back; return mTokensFrontBack.back;
} }

View File

@ -30,6 +30,7 @@
#include <list> #include <list>
#include <sstream> // IWYU pragma: keep #include <sstream> // IWYU pragma: keep
#include <string> #include <string>
#include <utility>
class Token; class Token;
@ -72,7 +73,7 @@ private:
class ScopedFile { class ScopedFile {
public: public:
ScopedFile(const std::string &name, const std::string &content) : mName(name) { ScopedFile(std::string name, const std::string &content) : mName(std::move(name)) {
std::ofstream of(mName); std::ofstream of(mName);
of << content; of << content;
} }