errortypes.h: use `enum class` instead of wrapping types into classes (#4693)

This commit is contained in:
Oliver Stöneberg 2023-01-08 19:31:54 +01:00 committed by GitHub
parent 911d610f2d
commit 8cc3e0b2ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 34 deletions

View File

@ -50,7 +50,7 @@ void Check::reportError(const ErrorMessage &errmsg)
} }
void Check::reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty) void Check::reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
{ {
const ErrorMessage errmsg(callstack, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty); const ErrorMessage errmsg(callstack, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
if (mErrorLogger) if (mErrorLogger)
@ -59,7 +59,7 @@ void Check::reportError(const std::list<const Token *> &callstack, Severity::Sev
reportError(errmsg); reportError(errmsg);
} }
void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty) void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
{ {
const ErrorMessage errmsg(errorPath, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty); const ErrorMessage errmsg(errorPath, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
if (mErrorLogger) if (mErrorLogger)

View File

@ -140,7 +140,7 @@ protected:
} }
/** report an error */ /** report an error */
void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty) { void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) {
const std::list<const Token *> callstack(1, tok); const std::list<const Token *> callstack(1, tok);
reportError(callstack, severity, id, msg, cwe, certainty); reportError(callstack, severity, id, msg, cwe, certainty);
} }
@ -151,9 +151,9 @@ protected:
} }
/** report an error */ /** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty); void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty);
void reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty); void reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty);
ErrorPath getErrorPath(const Token* errtok, const ValueFlow::Value* value, std::string bug) const; ErrorPath getErrorPath(const Token* errtok, const ValueFlow::Value* value, std::string bug) const;

View File

@ -678,7 +678,7 @@ void CheckBufferOverrun::bufferOverflow()
} }
} }
void CheckBufferOverrun::bufferOverflowError(const Token *tok, const ValueFlow::Value *value, const Certainty::CertaintyLevel &certainty) void CheckBufferOverrun::bufferOverflowError(const Token *tok, const ValueFlow::Value *value, Certainty certainty)
{ {
reportError(getErrorPath(tok, value, "Buffer overrun"), Severity::error, "bufferAccessOutOfBounds", "Buffer is accessed out of bounds: " + (tok ? tok->expressionString() : "buf"), CWE_BUFFER_OVERRUN, certainty); reportError(getErrorPath(tok, value, "Buffer overrun"), Severity::error, "bufferAccessOutOfBounds", "Buffer is accessed out of bounds: " + (tok ? tok->expressionString() : "buf"), CWE_BUFFER_OVERRUN, certainty);
} }

View File

@ -111,7 +111,7 @@ private:
void pointerArithmeticError(const Token *tok, const Token *indexToken, const ValueFlow::Value *indexValue); void pointerArithmeticError(const Token *tok, const Token *indexToken, const ValueFlow::Value *indexValue);
void bufferOverflow(); void bufferOverflow();
void bufferOverflowError(const Token *tok, const ValueFlow::Value *value, const Certainty::CertaintyLevel& certainty); void bufferOverflowError(const Token *tok, const ValueFlow::Value *value, Certainty certainty);
void arrayIndexThenCheck(); void arrayIndexThenCheck();
void arrayIndexThenCheckError(const Token *tok, const std::string &indexName); void arrayIndexThenCheckError(const Token *tok, const std::string &indexName);

View File

@ -43,7 +43,7 @@ ErrorMessage::ErrorMessage()
: severity(Severity::none), cwe(0U), certainty(Certainty::normal), hash(0) : severity(Severity::none), cwe(0U), certainty(Certainty::normal), hash(0)
{} {}
ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, Certainty::CertaintyLevel certainty) : ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, Certainty certainty) :
callStack(std::move(callStack)), // locations for this error message callStack(std::move(callStack)), // locations for this error message
id(std::move(id)), // set the message id id(std::move(id)), // set the message id
file0(std::move(file1)), file0(std::move(file1)),
@ -58,7 +58,7 @@ ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1,
ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, const CWE &cwe, Certainty::CertaintyLevel certainty) : ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, const CWE &cwe, Certainty certainty) :
callStack(std::move(callStack)), // locations for this error message callStack(std::move(callStack)), // locations for this error message
id(std::move(id)), // set the message id id(std::move(id)), // set the message id
file0(std::move(file1)), file0(std::move(file1)),
@ -71,7 +71,7 @@ ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1,
setmsg(msg); setmsg(msg);
} }
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, Certainty::CertaintyLevel certainty) ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, Certainty certainty)
: id(std::move(id)), severity(severity), cwe(0U), certainty(certainty), hash(0) : id(std::move(id)), severity(severity), cwe(0U), certainty(certainty), hash(0)
{ {
// Format callstack // Format callstack
@ -90,7 +90,7 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token
} }
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, const CWE &cwe, Certainty::CertaintyLevel certainty) ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, const CWE &cwe, Certainty certainty)
: id(std::move(id)), severity(severity), cwe(cwe.id), certainty(certainty) : id(std::move(id)), severity(severity), cwe(cwe.id), certainty(certainty)
{ {
// Format callstack // Format callstack
@ -110,7 +110,7 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token
hash = 0; // calculateWarningHash(list, hashWarning.str()); hash = 0; // calculateWarningHash(list, hashWarning.str());
} }
ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty) ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
: id(id), severity(severity), cwe(cwe.id), certainty(certainty) : id(id), severity(severity), cwe(cwe.id), certainty(certainty)
{ {
// Format callstack // Format callstack

View File

@ -112,34 +112,34 @@ public:
std::string file1, std::string file1,
Severity::SeverityType severity, Severity::SeverityType severity,
const std::string &msg, const std::string &msg,
std::string id, Certainty::CertaintyLevel certainty); std::string id, Certainty certainty);
ErrorMessage(std::list<FileLocation> callStack, ErrorMessage(std::list<FileLocation> callStack,
std::string file1, std::string file1,
Severity::SeverityType severity, Severity::SeverityType severity,
const std::string &msg, const std::string &msg,
std::string id, std::string id,
const CWE &cwe, const CWE &cwe,
Certainty::CertaintyLevel certainty); Certainty certainty);
ErrorMessage(const std::list<const Token*>& callstack, ErrorMessage(const std::list<const Token*>& callstack,
const TokenList* list, const TokenList* list,
Severity::SeverityType severity, Severity::SeverityType severity,
std::string id, std::string id,
const std::string& msg, const std::string& msg,
Certainty::CertaintyLevel certainty); Certainty certainty);
ErrorMessage(const std::list<const Token*>& callstack, ErrorMessage(const std::list<const Token*>& callstack,
const TokenList* list, const TokenList* list,
Severity::SeverityType severity, Severity::SeverityType severity,
std::string id, std::string id,
const std::string& msg, const std::string& msg,
const CWE &cwe, const CWE &cwe,
Certainty::CertaintyLevel certainty); Certainty certainty);
ErrorMessage(const ErrorPath &errorPath, ErrorMessage(const ErrorPath &errorPath,
const TokenList *tokenList, const TokenList *tokenList,
Severity::SeverityType severity, Severity::SeverityType severity,
const char id[], const char id[],
const std::string &msg, const std::string &msg,
const CWE &cwe, const CWE &cwe,
Certainty::CertaintyLevel certainty); Certainty certainty);
ErrorMessage(); ErrorMessage();
explicit ErrorMessage(const tinyxml2::XMLElement * const errmsg); explicit ErrorMessage(const tinyxml2::XMLElement * const errmsg);
@ -175,7 +175,7 @@ public:
Severity::SeverityType severity; Severity::SeverityType severity;
CWE cwe; CWE cwe;
Certainty::CertaintyLevel certainty; Certainty certainty;
/** Warning hash */ /** Warning hash */
std::size_t hash; std::size_t hash;

View File

@ -47,18 +47,12 @@ public:
TerminateException() : std::runtime_error("terminate") {} TerminateException() : std::runtime_error("terminate") {}
}; };
class CPPCHECKLIB Certainty { enum class Certainty {
public: normal, inconclusive, safe, experimental
enum CertaintyLevel {
normal, inconclusive, safe, experimental
};
}; };
class CPPCHECKLIB Checks { enum class Checks {
public: unusedFunction, missingInclude, internalCheck
enum CheckList {
unusedFunction, missingInclude, internalCheck
};
}; };
/** @brief enum class for severity. Used when reporting errors. */ /** @brief enum class for severity. Used when reporting errors. */

View File

@ -328,8 +328,8 @@ public:
SafeChecks safeChecks; SafeChecks safeChecks;
SimpleEnableGroup<Severity::SeverityType> severity; SimpleEnableGroup<Severity::SeverityType> severity;
SimpleEnableGroup<Certainty::CertaintyLevel> certainty; SimpleEnableGroup<Certainty> certainty;
SimpleEnableGroup<Checks::CheckList> checks; SimpleEnableGroup<Checks> checks;
/** @brief show timing information (--showtime=file|summary|top5) */ /** @brief show timing information (--showtime=file|summary|top5) */
SHOWTIME_MODES showtime; SHOWTIME_MODES showtime;

View File

@ -47,7 +47,7 @@ public:
return mFileName; return mFileName;
} }
int lineNumber; int lineNumber;
Certainty::CertaintyLevel certainty; Certainty certainty;
std::string symbolNames; std::string symbolNames;
private: private:
std::string mFileName; std::string mFileName;

View File

@ -254,7 +254,7 @@ private:
ASSERT_EQUALS("errorId", msg.id); ASSERT_EQUALS("errorId", msg.id);
ASSERT_EQUALS(Severity::error, msg.severity); ASSERT_EQUALS(Severity::error, msg.severity);
ASSERT_EQUALS(123u, msg.cwe.id); ASSERT_EQUALS(123u, msg.cwe.id);
ASSERT_EQUALS(Certainty::inconclusive, msg.certainty); ASSERT_EQUALS(static_cast<int>(Certainty::inconclusive), static_cast<int>(msg.certainty));
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS(456u, msg.hash); ASSERT_EQUALS(456u, msg.hash);
@ -303,7 +303,7 @@ private:
ASSERT_EQUALS("errorId", msg2.id); ASSERT_EQUALS("errorId", msg2.id);
ASSERT_EQUALS(Severity::error, msg2.severity); ASSERT_EQUALS(Severity::error, msg2.severity);
ASSERT_EQUALS("test.cpp", msg2.file0); ASSERT_EQUALS("test.cpp", msg2.file0);
ASSERT_EQUALS(Certainty::inconclusive, msg2.certainty); ASSERT_EQUALS(static_cast<int>(Certainty::inconclusive), static_cast<int>(msg2.certainty));
ASSERT_EQUALS("Programming error", msg2.shortMessage()); ASSERT_EQUALS("Programming error", msg2.shortMessage());
ASSERT_EQUALS("Programming error", msg2.verboseMessage()); ASSERT_EQUALS("Programming error", msg2.verboseMessage());
} }

View File

@ -98,7 +98,7 @@ private:
ret.errorId = errorId; ret.errorId = errorId;
ret.hash = 0; ret.hash = 0;
ret.lineNumber = 0; ret.lineNumber = 0;
ret.certainty = Certainty::CertaintyLevel::normal; ret.certainty = Certainty::normal;
return ret; return ret;
} }