diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 5a270d938ca..43da4f878c4 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1872,6 +1872,7 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger) CheckUnusedFunctions::getErrorMessages(errorlogger); Preprocessor::getErrorMessages(errorlogger, s); + Tokenizer::getErrorMessages(errorlogger, s); } void CppCheck::analyseClangTidy(const FileSettings &fileSettings) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 407edc3c97a..3cbc4419785 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1126,8 +1126,7 @@ void Tokenizer::simplifyTypedef() if (!ts.fail() && numberOfTypedefs[ts.name()] == 1 && (numberOfTypedefs.find(ts.getTypedefToken()->strAt(1)) == numberOfTypedefs.end() || ts.getTypedefToken()->strAt(2) == "(")) { if (mSettings.severity.isEnabled(Severity::portability) && ts.isInvalidConstFunctionType(typedefs)) - reportError(tok->next(), Severity::portability, "invalidConstFunctionType", - "It is unspecified behavior to const qualify a function type."); + invalidConstFunctionTypeError(tok->next()); typedefs.emplace(ts.name(), ts); if (!ts.isStructEtc()) tok = ts.endToken(); @@ -8139,6 +8138,14 @@ void Tokenizer::macroWithSemicolonError(const Token *tok, const std::string &mac "Ensure that '" + macroName + "' is defined either using -I, --include or -D."); } +void Tokenizer::invalidConstFunctionTypeError(const Token *tok) const +{ + reportError(tok, + Severity::portability, + "invalidConstFunctionType", + "It is unspecified behavior to const qualify a function type."); +} + void Tokenizer::cppcheckError(const Token *tok) const { printDebugOutput(0, std::cout); @@ -10899,3 +10906,13 @@ bool Tokenizer::isPacked(const Token * bodyStart) const return d.linenr < bodyStart->linenr() && d.str == "#pragma pack(1)" && d.file == list.getFiles().front(); }); } + +void Tokenizer::getErrorMessages(ErrorLogger& errorLogger, const Settings& settings) +{ + Tokenizer tokenizer(settings, errorLogger); + tokenizer.invalidConstFunctionTypeError(nullptr); + // checkLibraryNoReturn + tokenizer.unhandled_macro_class_x_y(nullptr); + tokenizer.macroWithSemicolonError(nullptr, emptyString); + tokenizer.unhandledCharLiteral(nullptr, emptyString); +} diff --git a/lib/tokenize.h b/lib/tokenize.h index 64c31ae73f4..cec6f94463b 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -396,6 +396,8 @@ class CPPCHECKLIB Tokenizer { void checkConfiguration() const; void macroWithSemicolonError(const Token *tok, const std::string ¯oName) const; + void invalidConstFunctionTypeError(const Token *tok) const; + /** * Is there C++ code in C file? */ @@ -628,6 +630,8 @@ class CPPCHECKLIB Tokenizer { void setDirectives(std::list directives); std::string dumpTypedefInfo() const; + + static void getErrorMessages(ErrorLogger& errorLogger, const Settings& settings); private: const Token *processFunc(const Token *tok2, bool inOperator) const; Token *processFunc(Token *tok2, bool inOperator);