diff --git a/.clang-tidy b/.clang-tidy index 0b130f31de08..d5054062dacc 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -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, diff --git a/clang-tidy.md b/clang-tidy.md index 108af31a354e..3cdfcbf9510a 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -129,7 +129,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as `performance-noexcept-swap`
`bugprone-switch-missing-default-case`
`bugprone-empty-catch`
-`performance-enum-size`
`readability-avoid-nested-conditional-operator`
To be evaluated (need to remove exclusion). diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index 4e41094ee101..607608de6cf0 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -20,6 +20,7 @@ #define CMDLINE_PARSER_H #include +#include #include #include #include @@ -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 diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index de847015ded1..0194fc55f4a9 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -56,7 +56,7 @@ #include #endif -enum class Color; +enum class Color : std::uint8_t ; // NOLINTNEXTLINE(misc-unused-using-decls) - required for FD_ZERO using std::memset; @@ -72,7 +72,7 @@ ProcessExecutor::ProcessExecutor(const std::list #include -enum class Color; +enum class Color : std::uint8_t ; ThreadExecutor::ThreadExecutor(const std::list> &files, const std::list& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand) : Executor(files, fileSettings, settings, suppressions, errorLogger) diff --git a/gui/checkthread.h b/gui/checkthread.h index 2b415bef6c51..21fe3b3da8c1 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -24,6 +24,7 @@ #include "suppressions.h" #include +#include #include #include @@ -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. */ diff --git a/gui/codeeditor.h b/gui/codeeditor.h index 6e06db9881f1..f627d8b4a795 100644 --- a/gui/codeeditor.h +++ b/gui/codeeditor.h @@ -19,6 +19,8 @@ #ifndef CODEEDITOR_H #define CODEEDITOR_H +#include + #include #include #include @@ -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, diff --git a/gui/cppchecklibrarydata.h b/gui/cppchecklibrarydata.h index 2ccf9d93ba30..a442780c3c2c 100644 --- a/gui/cppchecklibrarydata.h +++ b/gui/cppchecklibrarydata.h @@ -19,6 +19,8 @@ #ifndef CPPCHECKLIBRARYDATA_H #define CPPCHECKLIBRARYDATA_H +#include + #include #include #include @@ -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{}; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 5214b690ddca..7b3b164a9b0b 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -22,6 +22,8 @@ #include "library.h" #include "platforms.h" +#include + #include #include #include @@ -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; diff --git a/gui/newsuppressiondialog.cpp b/gui/newsuppressiondialog.cpp index 8635fc0ef0c1..7bd97431a848 100644 --- a/gui/newsuppressiondialog.cpp +++ b/gui/newsuppressiondialog.cpp @@ -31,7 +31,7 @@ #include class QWidget; -enum class Color; +enum class Color : std::uint8_t ; NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) : QDialog(parent), diff --git a/gui/projectfile.h b/gui/projectfile.h index df4d94fbbaa3..9e263e656495 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -23,6 +23,7 @@ #include "suppressions.h" #include +#include #include #include @@ -53,7 +54,7 @@ class ProjectFile : public QObject { if (this == mActiveProject) mActiveProject = nullptr; } - enum class CheckLevel { + enum class CheckLevel : std::uint8_t { normal, exhaustive }; diff --git a/gui/report.h b/gui/report.h index 5cea9be508fc..12823d257809 100644 --- a/gui/report.h +++ b/gui/report.h @@ -19,6 +19,8 @@ #ifndef REPORT_H #define REPORT_H +#include + #include #include #include @@ -33,7 +35,7 @@ class ErrorItem; */ class Report : public QObject { public: - enum Type { + enum Type : std::uint8_t { TXT, XMLV2, CSV, diff --git a/gui/resultstree.h b/gui/resultstree.h index 8d855766082c..96a40cb4d3c3 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -22,6 +22,8 @@ #include "showtypes.h" +#include + #include #include #include @@ -39,7 +41,7 @@ class ThreadHandler; class QContextMenuEvent; class QKeyEvent; class QSettings; -enum class Severity; +enum class Severity : std::uint8_t; /// @addtogroup GUI /// @{ diff --git a/gui/showtypes.h b/gui/showtypes.h index 605eaee17e1a..1d3829baa4d1 100644 --- a/gui/showtypes.h +++ b/gui/showtypes.h @@ -19,9 +19,11 @@ #ifndef SHOWTYPES_H #define SHOWTYPES_H +#include + #include -enum class Severity; +enum class Severity : std::uint8_t; /// @addtogroup GUI /// @{ @@ -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, diff --git a/lib/analyzer.h b/lib/analyzer.h index d6bcec727a7d..1b1a3074efd1 100644 --- a/lib/analyzer.h +++ b/lib/analyzer.h @@ -21,6 +21,8 @@ #include "config.h" #include "mathlib.h" + +#include #include #include #include @@ -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), @@ -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) @@ -146,10 +148,10 @@ 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), @@ -157,7 +159,7 @@ struct Analyzer { }; }; - 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; diff --git a/lib/astutils.h b/lib/astutils.h index 10699f8de61d..929ad41cd438 100644 --- a/lib/astutils.h +++ b/lib/astutils.h @@ -22,6 +22,7 @@ #define astutilsH //--------------------------------------------------------------------------- +#include #include #include #include @@ -39,7 +40,7 @@ class Settings; -enum class ChildrenToVisit { +enum class ChildrenToVisit : std::uint8_t { none, op1, op2, @@ -436,7 +437,7 @@ bool isConstVarExpression(const Token* tok, const std::function #include #include #include @@ -292,7 +293,7 @@ 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); @@ -300,7 +301,7 @@ class CPPCHECKLIB CheckClass : public Check { 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 diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index f5e250a0cd80..aaeb9d2fa489 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -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 diff --git a/lib/checkio.cpp b/lib/checkio.cpp index b4fc0a4abb62..f11dd8d34771 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -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) @@ -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) diff --git a/lib/checkio.h b/lib/checkio.h index cdc6b5e0e323..eba7c4e66e76 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -25,6 +25,7 @@ #include "config.h" #include "tokenize.h" +#include #include #include @@ -33,7 +34,7 @@ class Settings; class Token; class Variable; class ErrorLogger; -enum class Severity; +enum class Severity : std::uint8_t; /// @addtogroup Checks /// @{ diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index aee4e88ba6f6..eae2108d28aa 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -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; diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index 97aaff5722fb..946166fe91ca 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -27,6 +27,7 @@ #include "library.h" #include "tokenize.h" +#include #include #include #include @@ -38,7 +39,7 @@ class Token; class CPPCHECKLIB VarInfo { public: - enum AllocStatus { REALLOC = -3, OWNED = -2, DEALLOC = -1, NOALLOC = 0, ALLOC = 1 }; + enum AllocStatus : std::int8_t { REALLOC = -3, OWNED = -2, DEALLOC = -1, NOALLOC = 0, ALLOC = 1 }; struct AllocInfo { AllocStatus status; /** Allocation type. If it is a positive value then it corresponds to @@ -54,7 +55,7 @@ class CPPCHECKLIB VarInfo { return status < 0; } }; - enum Usage { USED, NORET }; + enum Usage : std::uint8_t { USED, NORET }; std::map alloctype; std::map> possibleUsage; std::set conditionalAlloc; diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 0360d9dcc6c6..a77c05d0d976 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -36,6 +36,7 @@ #include "config.h" #include "tokenize.h" +#include #include #include @@ -46,7 +47,7 @@ class Token; class Variable; class ErrorLogger; struct CWE; -enum class Severity; +enum class Severity : std::uint8_t; /// @addtogroup Core /// @{ @@ -92,7 +93,7 @@ class CPPCHECKLIB CheckMemoryLeak { : mTokenizer_(t), mErrorLogger_(e), mSettings_(s) {} /** @brief What type of allocation are used.. the "Many" means that several types of allocation and deallocation are used */ - enum AllocType { No, Malloc, New, NewArray, File, Fd, Pipe, OtherMem, OtherRes, Many }; + enum AllocType : std::uint8_t { No, Malloc, New, NewArray, File, Fd, Pipe, OtherMem, OtherRes, Many }; void memoryLeak(const Token *tok, const std::string &varname, AllocType alloctype) const; diff --git a/lib/checkother.cpp b/lib/checkother.cpp index beff69966686..dc6d630954cd 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1546,7 +1546,7 @@ void CheckOther::checkConstPointer() continue; pointers.emplace(var); const Token* parent = tok->astParent(); - enum Deref { NONE, DEREF, MEMBER } deref = NONE; + enum Deref : std::uint8_t { NONE, DEREF, MEMBER } deref = NONE; bool hasIncDec = false; if (parent && (parent->isUnaryOp("*") || (hasIncDec = parent->isIncDecOp() && parent->astParent() && parent->astParent()->isUnaryOp("*")))) deref = DEREF; diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 5eca694028fd..52d4ece35e64 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1990,7 +1990,7 @@ void CheckStl::string_c_str() if (scope.type != Scope::eFunction || !scope.function) continue; - enum {charPtr, stdString, stdStringConstRef, Other} returnType = Other; + enum : std::uint8_t {charPtr, stdString, stdStringConstRef, Other} returnType = Other; if (Token::Match(scope.function->tokenDef->tokAt(-2), "char|wchar_t *")) returnType = charPtr; else if (Token::Match(scope.function->tokenDef->tokAt(-5), "const std :: string|wstring &")) diff --git a/lib/checkstl.h b/lib/checkstl.h index 15e265b0edd8..fdb137e0f6fd 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -28,6 +28,7 @@ #include "tokenize.h" #include "vfvalue.h" +#include #include class Scope; @@ -224,7 +225,7 @@ class CPPCHECKLIB CheckStl : public Check { void uselessCallsReturnValueError(const Token* tok, const std::string& varname, const std::string& function); void uselessCallsSwapError(const Token* tok, const std::string& varname); - enum class SubstrErrorType { EMPTY, COPY, PREFIX, PREFIX_CONCAT }; + enum class SubstrErrorType : std::uint8_t { EMPTY, COPY, PREFIX, PREFIX_CONCAT }; void uselessCallsSubstrError(const Token* tok, SubstrErrorType type); void uselessCallsEmptyError(const Token* tok); void uselessCallsRemoveError(const Token* tok, const std::string& function); diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index 025cc9f119f4..ab546d3f103d 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -29,6 +29,7 @@ #include "tokenize.h" #include "vfvalue.h" +#include #include #include #include @@ -69,7 +70,7 @@ class CPPCHECKLIB CheckUninitVar : public Check { /** @brief This constructor is used when registering the CheckUninitVar */ CheckUninitVar() : Check(myName()) {} - enum Alloc { NO_ALLOC, NO_CTOR_CALL, CTOR_CALL, ARRAY }; + enum Alloc : std::uint8_t { NO_ALLOC, NO_CTOR_CALL, CTOR_CALL, ARRAY }; static const Token *isVariableUsage(const Token *vartok, const Library &library, bool pointer, Alloc alloc, int indirect = 0); const Token *isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect = 0) const; diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 15f989d8a996..0d080af307e7 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -101,7 +101,7 @@ static bool isRaiiClass(const ValueType *valueType, bool cpp, bool defaultReturn */ class Variables { public: - enum VariableType { standard, array, pointer, reference, pointerArray, referenceArray, pointerPointer, none }; + enum VariableType : std::uint8_t { standard, array, pointer, reference, pointerArray, referenceArray, pointerPointer, none }; /** Store information about variable usage */ class VariableUsage { diff --git a/lib/color.h b/lib/color.h index 247de299200a..96ce2ac716ca 100644 --- a/lib/color.h +++ b/lib/color.h @@ -21,10 +21,11 @@ #include "config.h" +#include #include #include -enum class Color { +enum class Color : std::uint8_t { Reset = 0, Bold = 1, Dim = 2, diff --git a/lib/cppcheck.h b/lib/cppcheck.h index ef68a9c4342b..9aef40dbee98 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -29,6 +29,7 @@ #include "settings.h" #include +#include #include #include #include @@ -40,7 +41,7 @@ #include class TokenList; -enum class SHOWTIME_MODES; +enum class SHOWTIME_MODES : std::uint8_t; struct FileSettings; class CheckUnusedFunctions; diff --git a/lib/ctu.h b/lib/ctu.h index 28e4421871c4..a5839251d1ea 100644 --- a/lib/ctu.h +++ b/lib/ctu.h @@ -28,6 +28,7 @@ #include "mathlib.h" #include "vfvalue.h" +#include #include #include #include @@ -51,7 +52,7 @@ namespace tinyxml2 { namespace CTU { class CPPCHECKLIB FileInfo : public Check::FileInfo { public: - enum class InvalidValueType { null, uninit, bufferOverflow }; + enum class InvalidValueType : std::uint8_t { null, uninit, bufferOverflow }; std::string toString() const override; diff --git a/lib/errortypes.h b/lib/errortypes.h index 3e9a6a41426e..0a13030c9f1f 100644 --- a/lib/errortypes.h +++ b/lib/errortypes.h @@ -23,6 +23,7 @@ #include "config.h" +#include #include #include #include @@ -34,7 +35,7 @@ class Token; /** @brief Simple container to be thrown when internal error is detected. */ struct CPPCHECKLIB InternalError { - enum Type {AST, SYNTAX, UNKNOWN_MACRO, INTERNAL, LIMIT, INSTANTIATION}; + enum Type : std::uint8_t {AST, SYNTAX, UNKNOWN_MACRO, INTERNAL, LIMIT, INSTANTIATION}; InternalError(const Token *tok, std::string errorMsg, Type type = INTERNAL); InternalError(const Token *tok, std::string errorMsg, std::string details, Type type = INTERNAL); @@ -51,16 +52,16 @@ class TerminateException : public std::runtime_error { TerminateException() : std::runtime_error("terminate") {} }; -enum class Certainty { +enum class Certainty : std::uint8_t { normal, inconclusive }; -enum class Checks { +enum class Checks : std::uint8_t { unusedFunction, missingInclude, internalCheck }; /** @brief enum class for severity. Used when reporting errors. */ -enum class Severity { +enum class Severity : std::uint8_t { /** * No severity (default value). */ diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index 92eedbe5098d..0680769c4f34 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -45,8 +45,8 @@ namespace { struct ForwardTraversal { - enum class Progress { Continue, Break, Skip }; - enum class Terminate { None, Bail, Inconclusive }; + enum class Progress : std::uint8_t { Continue, Break, Skip }; + enum class Terminate : std::uint8_t { None, Bail, Inconclusive }; ForwardTraversal(const ValuePtr& analyzer, const TokenList& tokenList, ErrorLogger* const errorLogger, const Settings& settings) : analyzer(analyzer), tokenList(tokenList), errorLogger(errorLogger), settings(settings) {} @@ -327,7 +327,7 @@ namespace { return r; } - enum class Status { + enum class Status : std::uint8_t { None, Inconclusive, }; diff --git a/lib/fwdanalysis.h b/lib/fwdanalysis.h index 17fc29f7b42c..9b612eb4cafb 100644 --- a/lib/fwdanalysis.h +++ b/lib/fwdanalysis.h @@ -23,6 +23,7 @@ #include "config.h" +#include #include #include @@ -73,7 +74,7 @@ class FwdAnalysis { /** Result of forward analysis */ struct Result { - enum class Type { NONE, READ, WRITE, BREAK, RETURN, BAILOUT } type; + enum class Type : std::uint8_t { NONE, READ, WRITE, BREAK, RETURN, BAILOUT } type; explicit Result(Type type) : type(type) {} Result(Type type, const Token *token) : type(type), token(token) {} const Token* token{}; @@ -83,7 +84,7 @@ class FwdAnalysis { Result checkRecursive(const Token *expr, const Token *startToken, const Token *endToken, const std::set &exprVarIds, bool local, bool inInnerClass, int depth=0); const Library &mLibrary; - enum class What { Reassign, UnusedValue, ValueFlow } mWhat = What::Reassign; + enum class What : std::uint8_t { Reassign, UnusedValue, ValueFlow } mWhat = What::Reassign; std::vector mValueFlow; bool mValueFlowKnown = true; }; diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 754dcb812d83..b085f05f3dbc 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -498,7 +498,7 @@ namespace { } std::string name; std::string configuration; - enum { Win32, x64, Unknown } platform = Unknown; + enum : std::uint8_t { Win32, x64, Unknown } platform = Unknown; std::string platformStr; }; diff --git a/lib/importproject.h b/lib/importproject.h index 54a8f6f0cd20..01ce274ec571 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -26,6 +26,7 @@ #include "platform.h" #include "utils.h" +#include #include #include #include @@ -51,7 +52,7 @@ class Settings; */ class CPPCHECKLIB WARN_UNUSED ImportProject { public: - enum class Type { + enum class Type : std::uint8_t { NONE, UNKNOWN, MISSING, diff --git a/lib/library.h b/lib/library.h index 11d59c676cde..fcc25eccbca9 100644 --- a/lib/library.h +++ b/lib/library.h @@ -25,6 +25,7 @@ #include "mathlib.h" #include "standards.h" +#include #include #include #include @@ -36,7 +37,7 @@ class Token; class Settings; -enum class Severity; +enum class Severity : std::uint8_t; namespace tinyxml2 { class XMLDocument; @@ -59,7 +60,7 @@ class CPPCHECKLIB Library { public: Library() = default; - enum class ErrorCode { + enum class ErrorCode : std::uint8_t { OK, FILE_NOT_FOUND, BAD_XML, UNKNOWN_ELEMENT, MISSING_ATTRIBUTE, BAD_ATTRIBUTE_VALUE, UNSUPPORTED_FORMAT, DUPLICATE_PLATFORM_TYPE, PLATFORM_TYPE_REDEFINED, DUPLICATE_DEFINE @@ -81,7 +82,7 @@ class CPPCHECKLIB Library { struct AllocFunc { int groupId; int arg; - enum class BufferSize {none,malloc,calloc,strdup}; + enum class BufferSize : std::uint8_t {none,malloc,calloc,strdup}; BufferSize bufferSize; int bufferSizeArg1; int bufferSizeArg2; @@ -178,7 +179,7 @@ class CPPCHECKLIB Library { bool isNotLibraryFunction(const Token *ftok) const; bool matchArguments(const Token *ftok, const std::string &functionName) const; - enum class UseRetValType { NONE, DEFAULT, ERROR_CODE }; + enum class UseRetValType : std::uint8_t { NONE, DEFAULT, ERROR_CODE }; UseRetValType getUseRetValType(const Token* ftok) const; const std::string& returnValue(const Token *ftok) const; @@ -195,7 +196,7 @@ class CPPCHECKLIB Library { public: Container() = default; - enum class Action { + enum class Action : std::uint8_t { RESIZE, CLEAR, PUSH, @@ -209,7 +210,7 @@ class CPPCHECKLIB Library { CHANGE_INTERNAL, NO_ACTION }; - enum class Yield { + enum class Yield : std::uint8_t { AT_INDEX, ITEM, BUFFER, @@ -290,7 +291,7 @@ class CPPCHECKLIB Library { IteratorInfo iteratorInfo; struct MinSize { - enum class Type { NONE, STRLEN, ARGVALUE, SIZEOF, MUL, VALUE }; + enum class Type : std::uint8_t { NONE, STRLEN, ARGVALUE, SIZEOF, MUL, VALUE }; MinSize(Type t, int a) : type(t), arg(a) {} Type type; int arg; @@ -300,7 +301,7 @@ class CPPCHECKLIB Library { }; std::vector minsizes; - enum class Direction { + enum class Direction : std::uint8_t { DIR_IN, ///< Input to called function. Data is treated as read-only. DIR_OUT, ///< Output to caller. Data is passed by reference or address and is potentially written. DIR_INOUT, ///< Input to called function, and output to caller. Data is passed by reference or address and is potentially modified. @@ -441,7 +442,7 @@ class CPPCHECKLIB Library { struct PodType { unsigned int size; char sign; - enum class Type { NO, BOOL, CHAR, SHORT, INT, LONG, LONGLONG } stdtype; + enum class Type : std::uint8_t { NO, BOOL, CHAR, SHORT, INT, LONG, LONGLONG } stdtype; }; const PodType *podtype(const std::string &name) const { const std::unordered_map::const_iterator it = mPodTypes.find(name); @@ -498,7 +499,7 @@ class CPPCHECKLIB Library { static bool isContainerYield(const Token * const cond, Library::Container::Yield y, const std::string& fallback=emptyString); /** Suppress/check a type */ - enum class TypeCheck { def, + enum class TypeCheck : std::uint8_t { def, check, suppress, checkFiniteLifetime, // (unusedvar) object has side effects, but immediate destruction is wrong @@ -564,7 +565,7 @@ class CPPCHECKLIB Library { int mOffset{}; std::set mBlocks; }; - enum class FalseTrueMaybe { False, True, Maybe }; + enum class FalseTrueMaybe : std::uint8_t { False, True, Maybe }; int mAllocId{}; std::set mFiles; std::map mAlloc; // allocation functions @@ -599,7 +600,7 @@ class CPPCHECKLIB Library { return (it == data.end()) ? nullptr : &it->second; } - enum DetectContainer { ContainerOnly, IteratorOnly, Both }; + enum DetectContainer : std::uint8_t { ContainerOnly, IteratorOnly, Both }; const Library::Container* detectContainerInternal(const Token* typeStart, DetectContainer detect, bool* isIterator = nullptr, bool withoutStd = false) const; }; diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index b56fdc07e0f2..242d6ef2cef9 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -541,7 +541,7 @@ bool MathLib::isDecimalFloat(const std::string &str) { if (str.empty()) return false; - enum class State { + enum class State : std::uint8_t { START, BASE_DIGITS1, LEADING_DECIMAL, TRAILING_DECIMAL, BASE_DIGITS2, E, MANTISSA_PLUSMINUS, MANTISSA_DIGITS, SUFFIX_F, SUFFIX_L, SUFFIX_LITERAL_LEADER, SUFFIX_LITERAL } state = State::START; std::string::const_iterator it = str.cbegin(); @@ -649,7 +649,7 @@ bool MathLib::isPositive(const std::string &str) static bool isValidIntegerSuffixIt(std::string::const_iterator it, std::string::const_iterator end, bool supportMicrosoftExtensions=true) { - enum class Status { START, SUFFIX_U, SUFFIX_UL, SUFFIX_ULL, SUFFIX_UZ, SUFFIX_L, SUFFIX_LU, SUFFIX_LL, SUFFIX_LLU, SUFFIX_I, SUFFIX_I6, SUFFIX_I64, SUFFIX_UI, SUFFIX_UI6, SUFFIX_UI64, SUFFIX_Z, SUFFIX_LITERAL_LEADER, SUFFIX_LITERAL } state = Status::START; + enum class Status : std::uint8_t { START, SUFFIX_U, SUFFIX_UL, SUFFIX_ULL, SUFFIX_UZ, SUFFIX_L, SUFFIX_LU, SUFFIX_LL, SUFFIX_LLU, SUFFIX_I, SUFFIX_I6, SUFFIX_I64, SUFFIX_UI, SUFFIX_UI6, SUFFIX_UI64, SUFFIX_Z, SUFFIX_LITERAL_LEADER, SUFFIX_LITERAL } state = Status::START; for (; it != end; ++it) { switch (state) { case Status::START: @@ -770,7 +770,7 @@ bool MathLib::isValidIntegerSuffix(const std::string& str, bool supportMicrosoft **/ bool MathLib::isOct(const std::string& str) { - enum class Status { + enum class Status : std::uint8_t { START, OCTAL_PREFIX, DIGITS } state = Status::START; if (str.empty()) @@ -805,7 +805,7 @@ bool MathLib::isOct(const std::string& str) bool MathLib::isIntHex(const std::string& str) { - enum class Status { + enum class Status : std::uint8_t { START, HEX_0, HEX_X, DIGIT } state = Status::START; if (str.empty()) @@ -846,7 +846,7 @@ bool MathLib::isIntHex(const std::string& str) bool MathLib::isFloatHex(const std::string& str) { - enum class Status { + enum class Status : std::uint8_t { START, HEX_0, HEX_X, WHOLE_NUMBER_DIGIT, POINT, FRACTION, EXPONENT_P, EXPONENT_SIGN, EXPONENT_DIGITS, EXPONENT_SUFFIX } state = Status::START; if (str.empty()) @@ -936,7 +936,7 @@ bool MathLib::isFloatHex(const std::string& str) **/ bool MathLib::isBin(const std::string& str) { - enum class Status { + enum class Status : std::uint8_t { START, GNU_BIN_PREFIX_0, GNU_BIN_PREFIX_B, DIGIT } state = Status::START; if (str.empty()) @@ -977,7 +977,7 @@ bool MathLib::isBin(const std::string& str) bool MathLib::isDec(const std::string & str) { - enum class Status { + enum class Status : std::uint8_t { START, DIGIT } state = Status::START; if (str.empty()) diff --git a/lib/mathlib.h b/lib/mathlib.h index 795250feaf1a..5a3ec0c5f69c 100644 --- a/lib/mathlib.h +++ b/lib/mathlib.h @@ -23,6 +23,7 @@ #include "config.h" +#include #include /// @addtogroup Core @@ -39,7 +40,7 @@ class CPPCHECKLIB MathLib { private: long long mIntValue{}; double mDoubleValue{}; - enum class Type { INT, LONG, LONGLONG, FLOAT } mType; + enum class Type : std::uint8_t { INT, LONG, LONGLONG, FLOAT } mType; bool mIsUnsigned{}; void promote(const value &v); diff --git a/lib/pathanalysis.h b/lib/pathanalysis.h index 94c3318a8269..d0415873be51 100644 --- a/lib/pathanalysis.h +++ b/lib/pathanalysis.h @@ -21,6 +21,7 @@ #include "errortypes.h" +#include #include #include #include @@ -30,7 +31,7 @@ class Scope; class Token; struct PathAnalysis { - enum class Progress { + enum class Progress : std::uint8_t { Continue, Break }; diff --git a/lib/platform.h b/lib/platform.h index 5e4e51e71f60..7f0f48e1a80a 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -25,6 +25,7 @@ #include "standards.h" #include +#include #include #include #include @@ -102,7 +103,7 @@ class CPPCHECKLIB Platform { char defaultSign; // unsigned:'u', signed:'s', unknown:'\0' - enum Type { + enum Type : std::uint8_t { Unspecified, // No platform specified Native, // whatever system this code was compiled on Win32A, diff --git a/lib/preprocessor.h b/lib/preprocessor.h index a902e1e953e6..15fb180b258e 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include #include #include @@ -80,7 +81,7 @@ class CPPCHECKLIB Preprocessor { /** * Include file types. */ - enum HeaderTypes { + enum HeaderTypes : std::uint8_t { UserHeader = 1, SystemHeader }; diff --git a/lib/settings.h b/lib/settings.h index a4aa03eee46b..ed6fc4b28497 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -43,7 +43,7 @@ #include #include -enum class SHOWTIME_MODES; +enum class SHOWTIME_MODES : std::uint8_t; namespace ValueFlow { class Value; } @@ -195,7 +195,7 @@ class CPPCHECKLIB WARN_UNUSED Settings { bool exceptionHandling{}; #endif - enum class ExecutorType + enum class ExecutorType : std::uint8_t { #ifdef HAS_THREADING_MODEL_THREAD Thread, @@ -466,7 +466,7 @@ class CPPCHECKLIB WARN_UNUSED Settings { void setCheckLevelExhaustive(); void setCheckLevelNormal(); - enum class CheckLevel { + enum class CheckLevel : std::uint8_t { exhaustive, normal }; diff --git a/lib/standards.h b/lib/standards.h index 4b1469164ca5..8cf4cd5458ca 100644 --- a/lib/standards.h +++ b/lib/standards.h @@ -23,6 +23,7 @@ #include "utils.h" +#include #include /// @addtogroup Core @@ -34,13 +35,13 @@ * This struct contains all possible standards that cppcheck recognize. */ struct Standards { - enum Language { None, C, CPP }; + enum Language : std::uint8_t { None, C, CPP }; /** C code standard */ - enum cstd_t { C89, C99, C11, CLatest = C11 } c = CLatest; + enum cstd_t : std::uint8_t { C89, C99, C11, CLatest = C11 } c = CLatest; /** C++ code standard */ - enum cppstd_t { CPP03, CPP11, CPP14, CPP17, CPP20, CPP23, CPPLatest = CPP23 } cpp = CPPLatest; + enum cppstd_t : std::uint8_t { CPP03, CPP11, CPP14, CPP17, CPP20, CPP23, CPPLatest = CPP23 } cpp = CPPLatest; /** --std value given on command line */ std::string stdValue; diff --git a/lib/suppressions.h b/lib/suppressions.h index bf50e5891c78..26262621706a 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -23,6 +23,7 @@ #include "config.h" #include +#include #include #include #include @@ -36,13 +37,13 @@ class Tokenizer; class ErrorMessage; class ErrorLogger; -enum class Certainty; +enum class Certainty : std::uint8_t; /** @brief class for handling suppressions */ class CPPCHECKLIB SuppressionList { public: - enum class Type { + enum class Type : std::uint8_t { unique, file, block, blockBegin, blockEnd, macro }; @@ -147,7 +148,7 @@ class CPPCHECKLIB SuppressionList { bool matched{}; bool checked{}; // for inline suppressions, checked or not - enum { NO_LINE = -1 }; + enum : std::int8_t { NO_LINE = -1 }; }; /** diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index ffa0777ecf59..ac6171e8ee4a 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -51,7 +52,7 @@ class ValueType; /** * @brief Access control enumerations. */ -enum class AccessControl { Public, Protected, Private, Global, Namespace, Argument, Local, Throw }; +enum class AccessControl : std::uint8_t { Public, Protected, Private, Global, Namespace, Argument, Local, Throw }; /** * @brief Array dimension information. @@ -68,7 +69,7 @@ class CPPCHECKLIB Type { const Token* classDef; ///< Points to "class" token const Scope* classScope; const Scope* enclosingScope; - enum class NeedInitialization { + enum class NeedInitialization : std::uint8_t { Unknown, True, False } needInitialization = NeedInitialization::Unknown; @@ -747,7 +748,7 @@ class CPPCHECKLIB Function { } public: - enum Type { eConstructor, eCopyConstructor, eMoveConstructor, eOperatorEqual, eDestructor, eFunction, eLambda }; + enum Type : std::uint8_t { eConstructor, eCopyConstructor, eMoveConstructor, eOperatorEqual, eDestructor, eFunction, eLambda }; Function(const Token *tok, const Scope *scope, const Token *tokDef, const Token *tokArgDef); Function(const Token *tokenDef, const std::string &clangType); @@ -1021,7 +1022,7 @@ class CPPCHECKLIB Scope { const Scope *scope; }; - enum ScopeType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eFor, eWhile, eDo, eSwitch, eUnconditional, eTry, eCatch, eLambda, eEnum }; + enum ScopeType : std::uint8_t { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eFor, eWhile, eDo, eSwitch, eUnconditional, eTry, eCatch, eLambda, eEnum }; Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_); Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_); @@ -1198,7 +1199,7 @@ class CPPCHECKLIB Scope { void getVariableList(const Settings& settings, const Token *start, const Token *end); }; -enum class Reference { +enum class Reference : std::uint8_t { None, LValue, RValue @@ -1207,8 +1208,8 @@ enum class Reference { /** Value type */ class CPPCHECKLIB ValueType { public: - enum Sign { UNKNOWN_SIGN, SIGNED, UNSIGNED } sign = UNKNOWN_SIGN; - enum Type { + enum Sign : std::uint8_t { UNKNOWN_SIGN, SIGNED, UNSIGNED } sign = UNKNOWN_SIGN; + enum Type : std::uint8_t { UNKNOWN_TYPE, POD, NONSTD, @@ -1278,7 +1279,7 @@ class CPPCHECKLIB ValueType { static Type typeFromString(const std::string &typestr, bool longType); - enum class MatchResult { UNKNOWN, SAME, FALLBACK1, FALLBACK2, NOMATCH }; + enum class MatchResult : std::uint8_t { UNKNOWN, SAME, FALLBACK1, FALLBACK2, NOMATCH }; static MatchResult matchParameter(const ValueType *call, const ValueType *func); static MatchResult matchParameter(const ValueType *call, const Variable *callVar, const Variable *funcVar); diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index e8e77507e5ed..c5ba74a8ddfc 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -24,6 +24,7 @@ #include "config.h" +#include #include #include #include @@ -77,7 +78,7 @@ class CPPCHECKLIB TemplateSimplifier { const Token *mParamEnd; unsigned int mFlags; - enum { + enum : std::uint16_t { fIsClass = (1 << 0), // class template fIsFunction = (1 << 1), // function template fIsVariable = (1 << 2), // variable template diff --git a/lib/timer.h b/lib/timer.h index a42f72b57a9a..28d3dffdac5b 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -22,12 +22,13 @@ #include "config.h" +#include #include #include #include #include -enum class SHOWTIME_MODES { +enum class SHOWTIME_MODES : std::uint8_t { SHOWTIME_NONE, SHOWTIME_FILE, SHOWTIME_FILE_TOTAL, diff --git a/lib/token.h b/lib/token.h index 4c5ceaba1112..0573425bf2e1 100644 --- a/lib/token.h +++ b/lib/token.h @@ -57,7 +57,7 @@ struct ScopeInfo2 { std::set usingNamespaces; }; -enum class TokenDebug { None, ValueFlow, ValueType }; +enum class TokenDebug : std::uint8_t { None, ValueFlow, ValueType }; struct TokenImpl { nonneg int mVarId{}; @@ -115,14 +115,14 @@ struct TokenImpl { // __cppcheck_in_range__ struct CppcheckAttributes { - enum Type { LOW, HIGH } type = LOW; + enum Type : std::uint8_t { LOW, HIGH } type = LOW; MathLib::bigint value{}; CppcheckAttributes* next{}; }; CppcheckAttributes* mCppcheckAttributes{}; // For memoization, to speed up parsing of huge arrays #8897 - enum class Cpp11init { UNKNOWN, CPP11INIT, NOINIT } mCpp11init = Cpp11init::UNKNOWN; + enum class Cpp11init : std::uint8_t { UNKNOWN, CPP11INIT, NOINIT } mCpp11init = Cpp11init::UNKNOWN; TokenDebug mDebug{}; @@ -157,7 +157,7 @@ class CPPCHECKLIB Token { Token(const Token &) = delete; Token& operator=(const Token &) = delete; - enum Type { + enum Type : std::uint8_t { eVariable, eType, eFunction, eKeyword, eName, // Names: Variable (varId), Type (typeId, later), Function (FuncId, later), Language keyword, Name (unknown identifier) eNumber, eString, eChar, eBoolean, eLiteral, eEnumerator, // Literals: Number, String, Character, Boolean, User defined literal (C++11), Enumerator eArithmeticalOp, eComparisonOp, eAssignmentOp, eLogicalOp, eBitOp, eIncDecOp, eExtendedOp, // Operators: Arithmetical, Comparison, Assignment, Logical, Bitwise, ++/--, Extended @@ -1328,7 +1328,7 @@ class CPPCHECKLIB Token { fIsInitComma = (1ULL << 42), // Is this comma located inside some {..}. i.e: {1,2,3,4} }; - enum : uint64_t { + enum : std::uint8_t { efMaxSize = sizeof(nonneg int) * 8, efIsUnique = efMaxSize - 2, }; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e921e997dccb..86d71062f012 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2388,7 +2388,7 @@ void Tokenizer::simplifyTypedefCpp() namespace { struct ScopeInfo3 { - enum Type { Global, Namespace, Record, MemberFunction, Other }; + enum Type : std::uint8_t { Global, Namespace, Record, MemberFunction, Other }; ScopeInfo3() : parent(nullptr), type(Global), bodyStart(nullptr), bodyEnd(nullptr) {} 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_) { diff --git a/lib/tokenize.h b/lib/tokenize.h index de8b6e8a1bc6..8c8df85e2db7 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -24,6 +24,7 @@ #include "config.h" #include "tokenlist.h" +#include #include #include #include @@ -37,7 +38,7 @@ class Token; class TemplateSimplifier; class ErrorLogger; class Preprocessor; -enum class Severity; +enum class Severity : std::uint8_t; /// @addtogroup Core /// @{ diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 87567f1f162d..890c46681f39 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1921,7 +1921,7 @@ void TokenList::simplifyPlatformTypes() const bool isCPP11 = isCPP() && (mSettings->standards.cpp >= Standards::CPP11); - enum { isLongLong, isLong, isInt } type; + enum : std::uint8_t { isLongLong, isLong, isInt } type; /** @todo This assumes a flat address space. Not true for segmented address space (FAR *). */ diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9876461df2c4..13549a6899bc 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3407,7 +3407,7 @@ struct MemberExpressionAnalyzer : SubExpressionAnalyzer { } }; -enum class LifetimeCapture { Undefined, ByValue, ByReference }; +enum class LifetimeCapture : std::uint8_t { Undefined, ByValue, ByReference }; static std::string lifetimeType(const Token *tok, const ValueFlow::Value *val) { diff --git a/lib/vfvalue.h b/lib/vfvalue.h index b3a7598cbedd..8abecac2a06e 100644 --- a/lib/vfvalue.h +++ b/lib/vfvalue.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,7 @@ namespace ValueFlow public: using ErrorPathItem = std::pair; using ErrorPath = std::list; - enum class Bound { Upper, Lower, Point }; + enum class Bound : std::uint8_t { Upper, Lower, Point }; explicit Value(long long val = 0, Bound b = Bound::Point) : bound(b), @@ -195,7 +196,7 @@ namespace ValueFlow std::string toString() const; - enum class ValueType { + enum class ValueType : std::uint8_t { INT, TOK, FLOAT, @@ -301,7 +302,7 @@ namespace ValueFlow int indirect{}; /** kind of moved */ - enum class MoveKind { NonMovedVariable, MovedVariable, ForwardedVariable } moveKind = MoveKind::NonMovedVariable; + enum class MoveKind : std::uint8_t { NonMovedVariable, MovedVariable, ForwardedVariable } moveKind = MoveKind::NonMovedVariable; /** Path id */ MathLib::bigint path{}; @@ -314,7 +315,7 @@ namespace ValueFlow // Set to where a lifetime is captured by value const Token* capturetok{}; - enum class LifetimeKind { + enum class LifetimeKind : std::uint8_t { // Pointer points to a member of lifetime Object, // A member of object points to the lifetime @@ -327,7 +328,7 @@ namespace ValueFlow Address } lifetimeKind = LifetimeKind::Object; - enum class LifetimeScope { Local, Argument, SubFunction, ThisPointer, ThisValue } lifetimeScope = LifetimeScope::Local; + enum class LifetimeScope : std::uint8_t { Local, Argument, SubFunction, ThisPointer, ThisValue } lifetimeScope = LifetimeScope::Local; static const char* toString(MoveKind moveKind); static const char* toString(LifetimeKind lifetimeKind); @@ -335,7 +336,7 @@ namespace ValueFlow static const char* toString(Bound bound); /** How known is this value */ - enum class ValueKind { + enum class ValueKind : std::uint8_t { /** This value is possible, other unlisted values may also be possible */ Possible, /** Only listed values are possible */ diff --git a/test/fixture.h b/test/fixture.h index af2276093630..d4dec6605dfb 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -40,8 +40,8 @@ class options; class Tokenizer; -enum class Certainty; -enum class Severity; +enum class Certainty : std::uint8_t; +enum class Severity : std::uint8_t; class TestFixture : public ErrorLogger { private: diff --git a/test/testastutils.cpp b/test/testastutils.cpp index 9140b16e5610..010072164f0a 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -453,7 +453,7 @@ class TestAstUtils : public TestFixture { ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a + 1)[b]; }", "+", ") [")); } - enum class Result {False, True, Fail}; + enum class Result : std::uint8_t {False, True, Fail}; Result isUsedAsBool(const char code[], const char pattern[]) { Tokenizer tokenizer(settingsDefault, this); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 3bcf6796ad07..6729cdfd0d2f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5904,7 +5904,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("a ? ( b < c ) : d > e", tokenizeAndStringify("a ? b < c : d > e")); } - enum class AstStyle { + enum class AstStyle : std::uint8_t { Simple, Z3 }; diff --git a/tools/dmake/dmake.cpp b/tools/dmake/dmake.cpp index 6de023f5cea4..ec2d1223a010 100644 --- a/tools/dmake/dmake.cpp +++ b/tools/dmake/dmake.cpp @@ -241,7 +241,7 @@ static int write_vcxproj(const std::string &proj_name, const std::function