diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index eb330b82f..1e18eac06 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -791,7 +791,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) if (message) { const tinyxml2::XMLElement *severity = message->FirstChildElement("severity"); if (severity) - rule.severity = Severity::fromString(severity->GetText()); + rule.severity = severityFromString(severity->GetText()); const tinyxml2::XMLElement *id = message->FirstChildElement("id"); if (id) diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index 2f79d1b7b..988a2ab4b 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -347,9 +347,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS errorItem.errorPath.last().line = r1MatchRes.captured(2).toInt(); errorItem.errorPath.last().column = r1MatchRes.captured(3).toInt(); if (r1MatchRes.captured(4) == "warning") - errorItem.severity = Severity::SeverityType::warning; + errorItem.severity = Severity::warning; else if (r1MatchRes.captured(4) == "error" || r1MatchRes.captured(4) == "fatal error") - errorItem.severity = Severity::SeverityType::error; + errorItem.severity = Severity::error; QString message,id; const QRegularExpressionMatch r2MatchRes = r2.match(r1MatchRes.captured(5)); @@ -362,13 +362,13 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS id = tool + '-' + r2MatchRes.captured(2); if (tool == CLANG_TIDY) { if (id1.startsWith("performance")) - errorItem.severity = Severity::SeverityType::performance; + errorItem.severity = Severity::performance; else if (id1.startsWith("portability")) - errorItem.severity = Severity::SeverityType::portability; + errorItem.severity = Severity::portability; else if (id1.startsWith("misc") && !id1.contains("unused")) - errorItem.severity = Severity::SeverityType::warning; + errorItem.severity = Severity::warning; else - errorItem.severity = Severity::SeverityType::style; + errorItem.severity = Severity::style; } } else { message = r1MatchRes.captured(5); diff --git a/gui/erroritem.h b/gui/erroritem.h index 5605f7ea6..507d7286d 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -37,12 +37,12 @@ */ class GuiSeverity { public: - static QString toString(Severity::SeverityType severity) { - return QString::fromStdString(Severity::toString(severity)); + static QString toString(Severity severity) { + return QString::fromStdString(severityToString(severity)); } - static Severity::SeverityType fromString(const QString &severity) { - return Severity::fromString(severity.toStdString()); + static Severity fromString(const QString &severity) { + return severityFromString(severity.toStdString()); } }; @@ -83,7 +83,7 @@ public: QString file0; QString errorId; - Severity::SeverityType severity; + Severity severity; bool inconclusive; QString summary; QString message; @@ -117,7 +117,7 @@ public: int cwe; unsigned long long hash; bool inconclusive; - Severity::SeverityType severity; + Severity severity; QString summary; QString message; QString sinceDate; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index ca4b6ec0b..b7ac15602 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -319,7 +319,7 @@ QStandardItem *ResultsTree::addBacktraceFiles(QStandardItem *parent, return list[0]; } -QString ResultsTree::severityToTranslatedString(Severity::SeverityType severity) +QString ResultsTree::severityToTranslatedString(Severity severity) { switch (severity) { case Severity::style: @@ -901,7 +901,7 @@ void ResultsTree::copy() QString inconclusive = data[INCONCLUSIVE].toBool() ? ",inconclusive" : ""; text += '[' + data[FILENAME].toString() + ':' + QString::number(data[LINE].toInt()) + "] (" - + QString::fromStdString(Severity::toString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data[SEVERITY].toInt()))) + inconclusive + + QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data[SEVERITY].toInt()))) + inconclusive + ") " + data[MESSAGE].toString() + " [" @@ -1155,7 +1155,7 @@ QString ResultsTree::getFilePath(const QStandardItem *target, bool fullPath) return QString(); } -QString ResultsTree::severityToIcon(Severity::SeverityType severity) +QString ResultsTree::severityToIcon(Severity severity) { switch (severity) { case Severity::error: diff --git a/gui/resultstree.h b/gui/resultstree.h index 23f7053b3..53ba09067 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -335,7 +335,7 @@ protected: * * @param severity Severity */ - static QString severityToIcon(Severity::SeverityType severity); + static QString severityToIcon(Severity severity); /** * @brief Helper function to open an error within target with application* @@ -382,7 +382,7 @@ protected: * @param severity Severity to convert * @return Severity as translated string */ - static QString severityToTranslatedString(Severity::SeverityType severity); + static QString severityToTranslatedString(Severity severity); /** * @brief Load all settings diff --git a/gui/showtypes.cpp b/gui/showtypes.cpp index 03d61c47e..d59b70843 100644 --- a/gui/showtypes.cpp +++ b/gui/showtypes.cpp @@ -32,7 +32,7 @@ ShowTypes::~ShowTypes() save(); } -ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severity) +ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity severity) { switch (severity) { case Severity::none: @@ -54,7 +54,7 @@ ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severit } } -Severity::SeverityType ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type) +Severity ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type) { switch (type) { case ShowTypes::ShowStyle: @@ -117,7 +117,7 @@ bool ShowTypes::isShown(ShowTypes::ShowType category) const return mVisible[category]; } -bool ShowTypes::isShown(Severity::SeverityType severity) const +bool ShowTypes::isShown(Severity severity) const { return isShown(ShowTypes::SeverityToShowType(severity)); } diff --git a/gui/showtypes.h b/gui/showtypes.h index d1e983361..3cff501cf 100644 --- a/gui/showtypes.h +++ b/gui/showtypes.h @@ -85,7 +85,7 @@ public: * @param severity severity to check. * @return true if the severity is visible. */ - bool isShown(Severity::SeverityType severity) const; + bool isShown(Severity severity) const; /** * @brief Show/hide the showtype. @@ -99,14 +99,14 @@ public: * @param severity Error severity * @return Severity converted to ShowTypes value */ - static ShowTypes::ShowType SeverityToShowType(Severity::SeverityType severity); + static ShowTypes::ShowType SeverityToShowType(Severity severity); /** * @brief Convert ShowType to severity string * @param type ShowType to convert * @return ShowType converted to severity */ - static Severity::SeverityType ShowTypeToSeverity(ShowTypes::ShowType type); + static Severity ShowTypeToSeverity(ShowTypes::ShowType type); /** * @brief Convert QVariant (that contains an int) to Showtypes value diff --git a/lib/check.cpp b/lib/check.cpp index 114ca8d71..53b4e5fed 100644 --- a/lib/check.cpp +++ b/lib/check.cpp @@ -61,7 +61,7 @@ void Check::writeToErrorList(const ErrorMessage &errmsg) } -void Check::reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) +void Check::reportError(const std::list &callstack, Severity 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); if (mErrorLogger) @@ -70,7 +70,7 @@ void Check::reportError(const std::list &callstack, Severity::Sev writeToErrorList(errmsg); } -void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty) +void Check::reportError(const ErrorPath &errorPath, Severity 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); if (mErrorLogger) diff --git a/lib/check.h b/lib/check.h index e98d1c7e3..91930a374 100644 --- a/lib/check.h +++ b/lib/check.h @@ -137,25 +137,25 @@ protected: ErrorLogger* const mErrorLogger{}; /** report an error */ - void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg) { + void reportError(const Token *tok, const Severity severity, const std::string &id, const std::string &msg) { reportError(tok, severity, id, msg, CWE(0U), Certainty::normal); } /** report an error */ - void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) { + void reportError(const Token *tok, const Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) { const std::list callstack(1, tok); reportError(callstack, severity, id, msg, cwe, certainty); } /** report an error */ - void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg) { + void reportError(const std::list &callstack, Severity severity, const std::string &id, const std::string &msg) { reportError(callstack, severity, id, msg, CWE(0U), Certainty::normal); } /** report an error */ - void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty); + void reportError(const std::list &callstack, Severity 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 certainty); + void reportError(const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty); /** log checker */ void logChecker(const char id[]); diff --git a/lib/checkio.cpp b/lib/checkio.cpp index e52f19871..583bbc23e 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1715,7 +1715,7 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok, nonneg int numFormat, nonneg int numFunction) { - const Severity::SeverityType severity = numFormat > numFunction ? Severity::error : Severity::warning; + const Severity severity = numFormat > numFunction ? Severity::error : Severity::warning; if (severity != Severity::error && !mSettings->severity.isEnabled(Severity::warning)) return; @@ -1749,7 +1749,7 @@ void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, cons void CheckIO::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1765,7 +1765,7 @@ void CheckIO::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat, } void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1810,7 +1810,7 @@ void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numForma } void CheckIO::invalidScanfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1829,7 +1829,7 @@ void CheckIO::invalidScanfArgTypeError_float(const Token* tok, nonneg int numFor void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1840,7 +1840,7 @@ void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat } void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1851,7 +1851,7 @@ void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat } void CheckIO::invalidPrintfArgTypeError_p(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1901,7 +1901,7 @@ static void printfFormatType(std::ostream& os, const std::string& specifier, boo void CheckIO::invalidPrintfArgTypeError_uint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1915,7 +1915,7 @@ void CheckIO::invalidPrintfArgTypeError_uint(const Token* tok, nonneg int numFor void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1928,7 +1928,7 @@ void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFor } void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo) { - const Severity::SeverityType severity = getSeverity(argInfo); + const Severity severity = getSeverity(argInfo); if (!mSettings->severity.isEnabled(severity)) return; std::ostringstream errmsg; @@ -1941,7 +1941,7 @@ void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFo reportError(tok, severity, "invalidPrintfArgType_float", errmsg.str(), CWE686, Certainty::normal); } -Severity::SeverityType CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo) +Severity CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo) { return (argInfo && argInfo->typeToken && !argInfo->typeToken->originalName().empty()) ? Severity::portability : Severity::warning; } diff --git a/lib/checkio.h b/lib/checkio.h index 8fb109283..3e9d15bb9 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -132,7 +132,7 @@ private: void invalidLengthModifierError(const Token* tok, nonneg int numFormat, const std::string& modifier); void invalidScanfFormatWidthError(const Token* tok, nonneg int numFormat, int width, const Variable *var, const std::string& specifier); static void argumentType(std::ostream & os, const ArgumentInfo * argInfo); - static Severity::SeverityType getSeverity(const ArgumentInfo *argInfo); + static Severity getSeverity(const ArgumentInfo *argInfo); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override { CheckIO c(nullptr, settings, errorLogger); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 553e91bc1..57aacdd2f 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -279,7 +279,7 @@ void CheckMemoryLeak::memoryLeak(const Token *tok, const std::string &varname, A } //--------------------------------------------------------------------------- -void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const +void CheckMemoryLeak::reportErr(const Token *tok, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const { std::list callstack; @@ -289,7 +289,7 @@ void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severit reportErr(callstack, severity, id, msg, cwe); } -void CheckMemoryLeak::reportErr(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const +void CheckMemoryLeak::reportErr(const std::list &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const { const ErrorMessage errmsg(callstack, mTokenizer_ ? &mTokenizer_->list : nullptr, severity, id, msg, cwe, Certainty::normal); if (mErrorLogger_) diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index c406ffccf..ef8e0564c 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -70,7 +70,7 @@ private: * @param msg text * @param cwe cwe number */ - void reportErr(const Token *tok, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const; + void reportErr(const Token *tok, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const; /** * Report error. Similar with the function Check::reportError @@ -80,7 +80,7 @@ private: * @param msg text * @param cwe cwe number */ - void reportErr(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const; + void reportErr(const std::list &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const; public: CheckMemoryLeak() = delete; diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 5ed81eb32..20338d19d 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -144,7 +144,7 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con } - Severity::SeverityType severity = rhsbits.errorSeverity() ? Severity::error : Severity::warning; + Severity severity = rhsbits.errorSeverity() ? Severity::error : Severity::warning; if (cpp14) severity = Severity::portability; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 35fa7363d..5a9e5fe22 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1429,8 +1429,8 @@ void CppCheck::executeAddons(const std::vector& files) const std::string text = obj["message"].get(); errmsg.setmsg(text); const std::string severity = obj["severity"].get(); - errmsg.severity = Severity::fromString(severity); - if (errmsg.severity == Severity::SeverityType::none) { + errmsg.severity = severityFromString(severity); + if (errmsg.severity == Severity::none) { if (!endsWith(errmsg.id, "-logChecker")) continue; } @@ -1672,13 +1672,13 @@ void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings) errmsg.id = "clang-tidy-" + errorString.substr(1, errorString.length() - 2); if (errmsg.id.find("performance") != std::string::npos) - errmsg.severity = Severity::SeverityType::performance; + errmsg.severity = Severity::performance; else if (errmsg.id.find("portability") != std::string::npos) - errmsg.severity = Severity::SeverityType::portability; + errmsg.severity = Severity::portability; else if (errmsg.id.find("cert") != std::string::npos || errmsg.id.find("misc") != std::string::npos || errmsg.id.find("unused") != std::string::npos) - errmsg.severity = Severity::SeverityType::warning; + errmsg.severity = Severity::warning; else - errmsg.severity = Severity::SeverityType::style; + errmsg.severity = Severity::style; errmsg.file0 = fixedpath; errmsg.setmsg(messageString); diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 91be7c24d..ccaf47807 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -58,7 +58,7 @@ ErrorMessage::ErrorMessage() {} // TODO: id and msg are swapped compared to other calls -ErrorMessage::ErrorMessage(std::list callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, Certainty certainty) : +ErrorMessage::ErrorMessage(std::list callStack, std::string file1, Severity severity, const std::string &msg, std::string id, Certainty certainty) : callStack(std::move(callStack)), // locations for this error message id(std::move(id)), // set the message id file0(std::move(file1)), @@ -73,7 +73,7 @@ ErrorMessage::ErrorMessage(std::list callStack, std::string file1, // TODO: id and msg are swapped compared to other calls -ErrorMessage::ErrorMessage(std::list callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, const CWE &cwe, Certainty certainty) : +ErrorMessage::ErrorMessage(std::list callStack, std::string file1, Severity severity, const std::string &msg, std::string id, const CWE &cwe, Certainty certainty) : callStack(std::move(callStack)), // locations for this error message id(std::move(id)), // set the message id file0(std::move(file1)), @@ -86,7 +86,7 @@ ErrorMessage::ErrorMessage(std::list callStack, std::string file1, setmsg(msg); } -ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, Certainty certainty) +ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity severity, std::string id, const std::string& msg, Certainty certainty) : id(std::move(id)), severity(severity), cwe(0U), certainty(certainty), hash(0) { // Format callstack @@ -105,7 +105,7 @@ ErrorMessage::ErrorMessage(const std::list& callstack, const Token } -ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, const CWE &cwe, Certainty certainty) +ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity severity, std::string id, const std::string& msg, const CWE &cwe, Certainty certainty) : id(std::move(id)), severity(severity), cwe(cwe.id), certainty(certainty) { // Format callstack @@ -125,7 +125,7 @@ ErrorMessage::ErrorMessage(const std::list& callstack, const Token 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 certainty) +ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty) : id(id), severity(severity), cwe(cwe.id), certainty(certainty) { // Format callstack @@ -165,7 +165,7 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) id = attr ? attr : unknown; attr = errmsg->Attribute("severity"); - severity = attr ? Severity::fromString(attr) : Severity::none; + severity = attr ? severityFromString(attr) : Severity::none; attr = errmsg->Attribute("cwe"); cwe.id = attr ? strToInt(attr) : 0; @@ -267,7 +267,7 @@ std::string ErrorMessage::serialize() const // Serialize this message into a simple string std::string oss; serializeString(oss, id); - serializeString(oss, Severity::toString(severity)); + serializeString(oss, severityToString(severity)); serializeString(oss, std::to_string(cwe.id)); serializeString(oss, std::to_string(hash)); serializeString(oss, file0); @@ -345,7 +345,7 @@ void ErrorMessage::deserialize(const std::string &data) throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - insufficient elements"); id = std::move(results[0]); - severity = Severity::fromString(results[1]); + severity = severityFromString(results[1]); cwe.id = 0; if (!results[2].empty()) { std::string err; @@ -483,7 +483,7 @@ std::string ErrorMessage::toXML() const tinyxml2::XMLPrinter printer(nullptr, false, 2); printer.OpenElement("error", false); printer.PushAttribute("id", id.c_str()); - printer.PushAttribute("severity", Severity::toString(severity).c_str()); + printer.PushAttribute("severity", severityToString(severity).c_str()); printer.PushAttribute("msg", fixInvalidChars(mShortMessage).c_str()); printer.PushAttribute("verbose", fixInvalidChars(mVerboseMessage).c_str()); if (cwe.id) @@ -629,7 +629,7 @@ std::string ErrorMessage::toString(bool verbose, const std::string &templateForm } if (severity != Severity::none) { text += '('; - text += Severity::toString(severity); + text += severityToString(severity); if (certainty == Certainty::inconclusive) text += ", inconclusive"; text += ") "; @@ -651,7 +651,7 @@ std::string ErrorMessage::toString(bool verbose, const std::string &templateForm findAndReplace(result, replaceFrom, replaceWith); pos1 = result.find("{inconclusive:", pos1); } - findAndReplace(result, "{severity}", Severity::toString(severity)); + findAndReplace(result, "{severity}", severityToString(severity)); findAndReplace(result, "{cwe}", std::to_string(cwe.id)); findAndReplace(result, "{message}", verbose ? mVerboseMessage : mShortMessage); if (!callStack.empty()) { @@ -882,7 +882,7 @@ std::string ErrorLogger::plistData(const ErrorMessage &msg) plist << " \r\n" << " description" << ErrorLogger::toxml(msg.shortMessage()) << "\r\n" - << " category" << Severity::toString(msg.severity) << "\r\n" + << " category" << severityToString(msg.severity) << "\r\n" << " type" << ErrorLogger::toxml(msg.shortMessage()) << "\r\n" << " check_name" << msg.id << "\r\n" << " \r\n" diff --git a/lib/errorlogger.h b/lib/errorlogger.h index ccc569c8c..44d9f3b8c 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -110,32 +110,32 @@ public: ErrorMessage(std::list callStack, std::string file1, - Severity::SeverityType severity, + Severity severity, const std::string &msg, std::string id, Certainty certainty); ErrorMessage(std::list callStack, std::string file1, - Severity::SeverityType severity, + Severity severity, const std::string &msg, std::string id, const CWE &cwe, Certainty certainty); ErrorMessage(const std::list& callstack, const TokenList* list, - Severity::SeverityType severity, + Severity severity, std::string id, const std::string& msg, Certainty certainty); ErrorMessage(const std::list& callstack, const TokenList* list, - Severity::SeverityType severity, + Severity severity, std::string id, const std::string& msg, const CWE &cwe, Certainty certainty); ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, - Severity::SeverityType severity, + Severity severity, const char id[], const std::string &msg, const CWE &cwe, @@ -173,7 +173,7 @@ public: /** For GUI rechecking; source file (not header) */ std::string file0; - Severity::SeverityType severity; + Severity severity; CWE cwe; Certainty certainty; diff --git a/lib/errortypes.cpp b/lib/errortypes.cpp index 1653df844..a7028d89b 100644 --- a/lib/errortypes.cpp +++ b/lib/errortypes.cpp @@ -47,47 +47,48 @@ InternalError::InternalError(const Token *tok, std::string errorMsg, std::string token(tok), errorMessage(std::move(errorMsg)), details(std::move(details)), type(type), id(typeToString(type)) {} -std::string Severity::toString(Severity::SeverityType severity) +std::string severityToString(Severity severity) { switch (severity) { - case none: + case Severity::none: return ""; - case error: + case Severity::error: return "error"; - case warning: + case Severity::warning: return "warning"; - case style: + case Severity::style: return "style"; - case performance: + case Severity::performance: return "performance"; - case portability: + case Severity::portability: return "portability"; - case information: + case Severity::information: return "information"; - case debug: + case Severity::debug: return "debug"; } throw InternalError(nullptr, "Unknown severity"); } -Severity::SeverityType Severity::fromString(const std::string& severity) + +Severity severityFromString(const std::string& severity) { if (severity.empty()) - return none; + return Severity::none; if (severity == "none") - return none; + return Severity::none; if (severity == "error") - return error; + return Severity::error; if (severity == "warning") - return warning; + return Severity::warning; if (severity == "style") - return style; + return Severity::style; if (severity == "performance") - return performance; + return Severity::performance; if (severity == "portability") - return portability; + return Severity::portability; if (severity == "information") - return information; + return Severity::information; if (severity == "debug") - return debug; - return none; + return Severity::debug; + return Severity::none; } diff --git a/lib/errortypes.h b/lib/errortypes.h index 2bb3a32c5..ff83d6a47 100644 --- a/lib/errortypes.h +++ b/lib/errortypes.h @@ -60,67 +60,61 @@ enum class Checks { }; /** @brief enum class for severity. Used when reporting errors. */ -class CPPCHECKLIB Severity { -public: +enum class Severity { /** - * Message severities. + * No severity (default value). */ - enum SeverityType { - /** - * No severity (default value). - */ - none, - /** - * Programming error. - * This indicates severe error like memory leak etc. - * The error is certain. - */ - error, - /** - * Warning. - * Used for dangerous coding style that can cause severe runtime errors. - * For example: forgetting to initialize a member variable in a constructor. - */ - warning, - /** - * Style warning. - * Used for general code cleanup recommendations. Fixing these - * will not fix any bugs but will make the code easier to maintain. - * For example: redundant code, unreachable code, etc. - */ - style, - /** - * Performance warning. - * Not an error as is but suboptimal code and fixing it probably leads - * to faster performance of the compiled code. - */ - performance, - /** - * Portability warning. - * This warning indicates the code is not properly portable for - * different platforms and bitnesses (32/64 bit). If the code is meant - * to compile in different platforms and bitnesses these warnings - * should be fixed. - */ - portability, - /** - * Checking information. - * Information message about the checking (process) itself. These - * messages inform about header files not found etc issues that are - * not errors in the code but something user needs to know. - */ - information, - /** - * Debug message. - * Debug-mode message useful for the developers. - */ - debug - }; - - static std::string toString(SeverityType severity); - static SeverityType fromString(const std::string &severity); + none, + /** + * Programming error. + * This indicates severe error like memory leak etc. + * The error is certain. + */ + error, + /** + * Warning. + * Used for dangerous coding style that can cause severe runtime errors. + * For example: forgetting to initialize a member variable in a constructor. + */ + warning, + /** + * Style warning. + * Used for general code cleanup recommendations. Fixing these + * will not fix any bugs but will make the code easier to maintain. + * For example: redundant code, unreachable code, etc. + */ + style, + /** + * Performance warning. + * Not an error as is but suboptimal code and fixing it probably leads + * to faster performance of the compiled code. + */ + performance, + /** + * Portability warning. + * This warning indicates the code is not properly portable for + * different platforms and bitnesses (32/64 bit). If the code is meant + * to compile in different platforms and bitnesses these warnings + * should be fixed. + */ + portability, + /** + * Checking information. + * Information message about the checking (process) itself. These + * messages inform about header files not found etc issues that are + * not errors in the code but something user needs to know. + */ + information, + /** + * Debug message. + * Debug-mode message useful for the developers. + */ + debug }; +CPPCHECKLIB std::string severityToString(Severity severity); +CPPCHECKLIB Severity severityFromString(const std::string &severity); + struct CWE { explicit CWE(unsigned short cweId) : id(cweId) {} unsigned short id; diff --git a/lib/library.cpp b/lib/library.cpp index b5699ff41..1bd06904d 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -837,7 +837,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co const char* const severity = functionnode->Attribute("severity"); if (severity == nullptr) return Error(ErrorCode::MISSING_ATTRIBUTE, "severity"); - wi.severity = Severity::fromString(severity); + wi.severity = severityFromString(severity); const char* const cstd = functionnode->Attribute("cstd"); if (cstd) { diff --git a/lib/library.h b/lib/library.h index 7cd68a8f6..e45683a56 100644 --- a/lib/library.h +++ b/lib/library.h @@ -164,7 +164,7 @@ public: struct WarnInfo { std::string message; Standards standards; - Severity::SeverityType severity; + Severity severity; }; std::map functionwarn; diff --git a/lib/settings.cpp b/lib/settings.cpp index 18519bad2..c0cf5da27 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -75,7 +75,7 @@ void Settings::loadCppcheckCfg() } } -std::string Settings::parseEnabled(const std::string &str, std::tuple, SimpleEnableGroup> &groups) +std::string Settings::parseEnabled(const std::string &str, std::tuple, SimpleEnableGroup> &groups) { // Enable parameters may be comma separated... if (str.find(',') != std::string::npos) { @@ -100,9 +100,9 @@ std::string Settings::parseEnabled(const std::string &str, std::tuple newSeverity; + SimpleEnableGroup newSeverity; newSeverity.fill(); - newSeverity.disable(Severity::SeverityType::error); + newSeverity.disable(Severity::error); severity.enable(newSeverity); checks.enable(Checks::missingInclude); checks.enable(Checks::unusedFunction); @@ -148,7 +148,7 @@ std::string Settings::removeEnabled(const std::string &str) std::string Settings::applyEnabled(const std::string &str, bool enable) { - std::tuple, SimpleEnableGroup> groups; + std::tuple, SimpleEnableGroup> groups; std::string errmsg = parseEnabled(str, groups); if (!errmsg.empty()) return (enable ? "--enable" : "--disable") + errmsg; @@ -164,7 +164,7 @@ std::string Settings::applyEnabled(const std::string &str, bool enable) checks.disable(c); } // FIXME: hack to make sure "error" is always enabled - severity.enable(Severity::SeverityType::error); + severity.enable(Severity::error); return errmsg; } diff --git a/lib/settings.h b/lib/settings.h index 900fd61cf..f5bf7a5d3 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -282,7 +282,7 @@ public: std::string pattern; std::string id = "rule"; // default id std::string summary; - Severity::SeverityType severity = Severity::style; // default severity + Severity severity = Severity::style; // default severity }; #ifdef HAVE_RULES @@ -335,7 +335,7 @@ public: SafeChecks safeChecks; - SimpleEnableGroup severity; + SimpleEnableGroup severity; SimpleEnableGroup certainty; SimpleEnableGroup checks; @@ -439,7 +439,7 @@ public: void setCheckLevelNormal(); private: - static std::string parseEnabled(const std::string &str, std::tuple, SimpleEnableGroup> &groups); + static std::string parseEnabled(const std::string &str, std::tuple, SimpleEnableGroup> &groups); std::string applyEnabled(const std::string &str, bool enable); }; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7e319e4de..4766f4add 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10274,13 +10274,13 @@ void Tokenizer::prepareTernaryOpForAST() } } -void Tokenizer::reportError(const Token* tok, const Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) const +void Tokenizer::reportError(const Token* tok, const Severity severity, const std::string& id, const std::string& msg, bool inconclusive) const { const std::list callstack(1, tok); reportError(callstack, severity, id, msg, inconclusive); } -void Tokenizer::reportError(const std::list& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) const +void Tokenizer::reportError(const std::list& callstack, Severity severity, const std::string& id, const std::string& msg, bool inconclusive) const { const ErrorMessage errmsg(callstack, &list, severity, id, msg, inconclusive ? Certainty::inconclusive : Certainty::normal); if (mErrorLogger) diff --git a/lib/tokenize.h b/lib/tokenize.h index 9ce946ff7..07b526ca0 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -572,8 +572,8 @@ private: /** * report error message */ - void reportError(const Token* tok, const Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive = false) const; - void reportError(const std::list& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive = false) const; + void reportError(const Token* tok, const Severity severity, const std::string& id, const std::string& msg, bool inconclusive = false) const; + void reportError(const std::list& callstack, Severity severity, const std::string& id, const std::string& msg, bool inconclusive = false) const; bool duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef) const; diff --git a/test/fixture.h b/test/fixture.h index 4e5f7262d..039a4a2c0 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -138,7 +138,7 @@ protected: explicit SettingsBuilder(const TestFixture &fixture) : fixture(fixture) {} SettingsBuilder(const TestFixture &fixture, Settings settings) : fixture(fixture), settings(std::move(settings)) {} - SettingsBuilder& severity(Severity::SeverityType sev, bool b = true) { + SettingsBuilder& severity(Severity sev, bool b = true) { if (REDUNDANT_CHECK && settings.severity.isEnabled(sev) == b) throw std::runtime_error("redundant setting: severity"); settings.severity.setEnabled(sev, b); diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 78a7ae474..52ef7e703 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -281,7 +281,7 @@ private: ASSERT(doc.Parse(xmldata, sizeof(xmldata)) == tinyxml2::XML_SUCCESS); ErrorMessage msg(doc.FirstChildElement()); ASSERT_EQUALS("errorId", msg.id); - ASSERT_EQUALS(Severity::error, msg.severity); + ASSERT_EQUALS(static_cast(Severity::error), static_cast(msg.severity)); ASSERT_EQUALS(123u, msg.cwe.id); ASSERT_EQUALS(static_cast(Certainty::inconclusive), static_cast(msg.certainty)); ASSERT_EQUALS("Programming error.", msg.shortMessage()); @@ -330,7 +330,7 @@ private: ErrorMessage msg2; ASSERT_NO_THROW(msg2.deserialize(msg_str)); ASSERT_EQUALS("errorId", msg2.id); - ASSERT_EQUALS(Severity::error, msg2.severity); + ASSERT_EQUALS(static_cast(Severity::error), static_cast(msg2.severity)); ASSERT_EQUALS("test.cpp", msg2.file0); ASSERT_EQUALS(static_cast(Certainty::inconclusive), static_cast(msg2.certainty)); ASSERT_EQUALS("Programming error", msg2.shortMessage()); @@ -418,7 +418,7 @@ private: ErrorMessage msg2; ASSERT_NO_THROW(msg2.deserialize(msg_str)); ASSERT_EQUALS("errorId", msg2.id); - ASSERT_EQUALS(Severity::error, msg2.severity); + ASSERT_EQUALS(static_cast(Severity::error), static_cast(msg2.severity)); ASSERT_EQUALS("1.c", msg2.file0); ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.shortMessage()); ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.verboseMessage()); diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index f4bb1cab9..508ee938d 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -645,12 +645,12 @@ private: ASSERT(a && b); if (a && b) { ASSERT_EQUALS("Message", a->message); - ASSERT_EQUALS(Severity::style, a->severity); + ASSERT_EQUALS(static_cast(Severity::style), static_cast(a->severity)); ASSERT_EQUALS(Standards::C99, a->standards.c); ASSERT_EQUALS(Standards::CPP03, a->standards.cpp); ASSERT_EQUALS("Obsolescent function 'b' called. It is recommended to use 'c', 'd' or 'e' instead.", b->message); - ASSERT_EQUALS(Severity::performance, b->severity); + ASSERT_EQUALS(static_cast(Severity::performance), static_cast(b->severity)); ASSERT_EQUALS(Standards::C89, b->standards.c); ASSERT_EQUALS(Standards::CPP11, b->standards.cpp); }