Skip to content

Commit

Permalink
enabled and fixed performance-enum-size clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 2, 2024
1 parent 5c5d6a8 commit 41d6b55
Show file tree
Hide file tree
Showing 59 changed files with 157 additions and 117 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Checks: >
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-performance-avoid-endl,
-performance-enum-size,
-performance-inefficient-string-concatenation,
-performance-no-automatic-move,
-performance-noexcept-swap,
Expand Down
1 change: 0 additions & 1 deletion clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as
`performance-noexcept-swap`<br/>
`bugprone-switch-missing-default-case`<br/>
`bugprone-empty-catch`<br/>
`performance-enum-size`<br/>
`readability-avoid-nested-conditional-operator`</br>

To be evaluated (need to remove exclusion).
Expand Down
3 changes: 2 additions & 1 deletion cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CMDLINE_PARSER_H

#include <cstddef>
#include <cstdint>
#include <list>
#include <string>
#include <utility>
Expand Down Expand Up @@ -56,7 +57,7 @@ class CmdLineParser {
*/
CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions);

enum class Result { Success, Exit, Fail };
enum class Result : std::uint8_t { Success, Exit, Fail };

/**
* @brief Parse command line args and fill settings and file lists
Expand Down
4 changes: 2 additions & 2 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include <sys/prctl.h>
#endif

enum class Color;
enum class Color : std::uint8_t ;

// NOLINTNEXTLINE(misc-unused-using-decls) - required for FD_ZERO
using std::memset;
Expand All @@ -72,7 +72,7 @@ ProcessExecutor::ProcessExecutor(const std::list<std::pair<std::string, std::siz
namespace {
class PipeWriter : public ErrorLogger {
public:
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};
enum PipeSignal : std::uint8_t {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};

explicit PipeWriter(int pipe) : mWpipe(pipe) {}

Expand Down
2 changes: 1 addition & 1 deletion cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <utility>
#include <vector>

enum class Color;
enum class Color : std::uint8_t ;

ThreadExecutor::ThreadExecutor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
Expand Down
3 changes: 2 additions & 1 deletion gui/checkthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "suppressions.h"

#include <atomic>
#include <cstdint>
#include <string>
#include <vector>

Expand Down Expand Up @@ -115,7 +116,7 @@ class CheckThread : public QThread {
* has been completed. Thread must be stopped cleanly, just terminating thread
* likely causes unpredictable side-effects.
*/
enum State {
enum State : std::uint8_t {
Running, /**< The thread is checking. */
Stopping, /**< The thread will stop after current work. */
Stopped, /**< The thread has been stopped. */
Expand Down
4 changes: 3 additions & 1 deletion gui/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef CODEEDITOR_H
#define CODEEDITOR_H

#include <cstdint>

#include <QObject>
#include <QPlainTextEdit>
#include <QRegularExpression>
Expand Down Expand Up @@ -51,7 +53,7 @@ class Highlighter : public QSyntaxHighlighter {
void highlightBlock(const QString &text) override;

private:
enum RuleRole {
enum RuleRole : std::uint8_t {
Keyword = 1,
Class = 2,
Comment = 3,
Expand Down
4 changes: 3 additions & 1 deletion gui/cppchecklibrarydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef CPPCHECKLIBRARYDATA_H
#define CPPCHECKLIBRARYDATA_H

#include <cstdint>

#include <QList>
#include <QMap>
#include <QPair>
Expand Down Expand Up @@ -72,7 +74,7 @@ class CppcheckLibraryData {
struct Function {
QString comments;
QString name;
enum TrueFalseUnknown { False, True, Unknown } noreturn = Unknown;
enum TrueFalseUnknown : std::uint8_t { False, True, Unknown } noreturn = Unknown;
bool gccPure{};
bool gccConst{};
bool leakignore{};
Expand Down
4 changes: 3 additions & 1 deletion gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "library.h"
#include "platforms.h"

#include <cstdint>

#include <QFileDialog>
#include <QMainWindow>
#include <QObject>
Expand Down Expand Up @@ -62,7 +64,7 @@ class MainWindow : public QMainWindow {
/**
* @brief Maximum number of MRU project items in File-menu.
*/
enum { MaxRecentProjects = 5 };
enum : std::uint8_t { MaxRecentProjects = 5 };

MainWindow(TranslationHandler* th, QSettings* settings);
MainWindow(const MainWindow &) = delete;
Expand Down
2 changes: 1 addition & 1 deletion gui/newsuppressiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <QStringList>

class QWidget;
enum class Color;
enum class Color : std::uint8_t ;

NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
QDialog(parent),
Expand Down
3 changes: 2 additions & 1 deletion gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "suppressions.h"

#include <cstddef>
#include <cstdint>
#include <map>
#include <utility>

Expand Down Expand Up @@ -53,7 +54,7 @@ class ProjectFile : public QObject {
if (this == mActiveProject) mActiveProject = nullptr;
}

enum class CheckLevel {
enum class CheckLevel : std::uint8_t {
normal,
exhaustive
};
Expand Down
4 changes: 3 additions & 1 deletion gui/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef REPORT_H
#define REPORT_H

#include <cstdint>

#include <QFile>
#include <QObject>
#include <QString>
Expand All @@ -33,7 +35,7 @@ class ErrorItem;
*/
class Report : public QObject {
public:
enum Type {
enum Type : std::uint8_t {
TXT,
XMLV2,
CSV,
Expand Down
4 changes: 3 additions & 1 deletion gui/resultstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "showtypes.h"

#include <cstdint>

#include <QObject>
#include <QStandardItemModel>
#include <QString>
Expand All @@ -39,7 +41,7 @@ class ThreadHandler;
class QContextMenuEvent;
class QKeyEvent;
class QSettings;
enum class Severity;
enum class Severity : std::uint8_t;

/// @addtogroup GUI
/// @{
Expand Down
6 changes: 4 additions & 2 deletions gui/showtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
#ifndef SHOWTYPES_H
#define SHOWTYPES_H

#include <cstdint>

#include <QVariant>

enum class Severity;
enum class Severity : std::uint8_t;

/// @addtogroup GUI
/// @{
Expand All @@ -41,7 +43,7 @@ class ShowTypes {
/**
* @brief Show types we have (i.e. severities in the GUI).
*/
enum ShowType {
enum ShowType : std::uint8_t {
ShowStyle = 0,
ShowWarnings,
ShowPerformance,
Expand Down
12 changes: 7 additions & 5 deletions lib/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "config.h"
#include "mathlib.h"

#include <cstdint>
#include <string>
#include <type_traits>
#include <vector>
Expand All @@ -43,7 +45,7 @@ struct Analyzer {
Action(T f) : mFlag(f) // cppcheck-suppress noExplicitConstructor
{}

enum {
enum : std::uint16_t {
None = 0,
Read = (1 << 0),
Write = (1 << 1),
Expand Down Expand Up @@ -130,7 +132,7 @@ struct Analyzer {
unsigned int mFlag{};
};

enum class Terminate { None, Bail, Escape, Modified, Inconclusive, Conditional };
enum class Terminate : std::uint8_t { None, Bail, Escape, Modified, Inconclusive, Conditional };

struct Result {
explicit Result(Action action = Action::None, Terminate terminate = Terminate::None)
Expand All @@ -146,18 +148,18 @@ struct Analyzer {
}
};

enum class Direction { Forward, Reverse };
enum class Direction : std::uint8_t { Forward, Reverse };

struct Assume {
enum Flags {
enum Flags : std::uint8_t {
None = 0,
Quiet = (1 << 0),
Absolute = (1 << 1),
ContainerEmpty = (1 << 2),
};
};

enum class Evaluate { Integral, ContainerEmpty };
enum class Evaluate : std::uint8_t { Integral, ContainerEmpty };

/// Analyze a token
virtual Action analyze(const Token* tok, Direction d) const = 0;
Expand Down
5 changes: 3 additions & 2 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define astutilsH
//---------------------------------------------------------------------------

#include <cstdint>
#include <functional>
#include <list>
#include <stack>
Expand All @@ -39,7 +40,7 @@

class Settings;

enum class ChildrenToVisit {
enum class ChildrenToVisit : std::uint8_t {
none,
op1,
op2,
Expand Down Expand Up @@ -436,7 +437,7 @@ bool isConstVarExpression(const Token* tok, const std::function<bool(const Token

bool isLeafDot(const Token* tok);

enum class ExprUsage { None, NotUsed, PassedByReference, Used, Inconclusive };
enum class ExprUsage : std::uint8_t { None, NotUsed, PassedByReference, Used, Inconclusive };

ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings);

Expand Down
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3075,7 +3075,7 @@ void CheckClass::duplInheritedMembersError(const Token *tok1, const Token* tok2,
// Check that copy constructor and operator defined together
//---------------------------------------------------------------------------

enum class CtorType {
enum class CtorType : std::uint8_t {
NO,
WITHOUT_BODY,
WITH_BODY
Expand Down
5 changes: 3 additions & 2 deletions lib/checkclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "tokenize.h"
#include "symboldatabase.h"

#include <cstdint>
#include <list>
#include <map>
#include <set>
Expand Down Expand Up @@ -292,15 +293,15 @@ class CPPCHECKLIB CheckClass : public Check {
bool hasAllocation(const Function *func, const Scope* scope, const Token *start, const Token *end) const;
bool hasAllocationInIfScope(const Function *func, const Scope* scope, const Token *ifStatementScopeStart) const;
static bool hasAssignSelf(const Function *func, const Token *rhs, const Token **out_ifStatementScopeStart);
enum class Bool { TRUE, FALSE, BAILOUT };
enum class Bool : std::uint8_t { TRUE, FALSE, BAILOUT };
static Bool isInverted(const Token *tok, const Token *rhs);
static const Token * getIfStmtBodyStart(const Token *tok, const Token *rhs);

// checkConst helper functions
bool isMemberVar(const Scope *scope, const Token *tok) const;
static bool isMemberFunc(const Scope *scope, const Token *tok);
static bool isConstMemberFunc(const Scope *scope, const Token *tok);
enum class MemberAccess { NONE, SELF, MEMBER };
enum class MemberAccess : std::uint8_t { NONE, SELF, MEMBER };
bool checkConstFunc(const Scope *scope, const Function *func, MemberAccess& memberAccessed) const;

// constructors helper function
Expand Down
2 changes: 1 addition & 1 deletion lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ void CheckCondition::multiCondition2()
});

// parse until second condition is reached..
enum MULTICONDITIONTYPE { INNER, AFTER };
enum MULTICONDITIONTYPE : std::uint8_t { INNER, AFTER };
const Token *tok;

// Parse inner condition first and then early return condition
Expand Down
6 changes: 3 additions & 3 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void CheckIO::coutCerrMisusageError(const Token* tok, const std::string& streamN
// fopen("","r"); fwrite(); <- write to read-only file (or vice versa)
// fclose(); fread(); <- Use closed file
//---------------------------------------------------------------------------
enum class OpenMode { CLOSED, READ_MODE, WRITE_MODE, RW_MODE, UNKNOWN_OM };
enum class OpenMode : std::uint8_t { CLOSED, READ_MODE, WRITE_MODE, RW_MODE, UNKNOWN_OM };
static OpenMode getMode(const std::string& str)
{
if (str.find('+', 1) != std::string::npos)
Expand All @@ -112,9 +112,9 @@ namespace {
struct Filepointer {
OpenMode mode;
nonneg int mode_indent{};
enum class Operation {NONE, UNIMPORTANT, READ, WRITE, POSITIONING, OPEN, CLOSE, UNKNOWN_OP} lastOperation = Operation::NONE;
enum class Operation : std::uint8_t {NONE, UNIMPORTANT, READ, WRITE, POSITIONING, OPEN, CLOSE, UNKNOWN_OP} lastOperation = Operation::NONE;
nonneg int op_indent{};
enum class AppendMode { UNKNOWN_AM, APPEND, APPEND_EX };
enum class AppendMode : std::uint8_t { UNKNOWN_AM, APPEND, APPEND_EX };
AppendMode append_mode = AppendMode::UNKNOWN_AM;
std::string filename;
explicit Filepointer(OpenMode mode_ = OpenMode::UNKNOWN_OM)
Expand Down
3 changes: 2 additions & 1 deletion lib/checkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "config.h"
#include "tokenize.h"

#include <cstdint>
#include <ostream>
#include <string>

Expand All @@ -33,7 +34,7 @@ class Settings;
class Token;
class Variable;
class ErrorLogger;
enum class Severity;
enum class Severity : std::uint8_t;

/// @addtogroup Checks
/// @{
Expand Down
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO
// don't warn if we leave an inner scope
if (isEndOfScope && var->scope() && tok != var->scope()->bodyEnd)
continue;
enum class PtrUsage { NONE, DEREF, PTR } used = PtrUsage::NONE;
enum class PtrUsage : std::uint8_t { NONE, DEREF, PTR } used = PtrUsage::NONE;
for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) {
if (tok2->str() == ";")
break;
Expand Down
Loading

0 comments on commit 41d6b55

Please sign in to comment.