Skip to content

Commit

Permalink
fixed #13420 - Tokenizer did not contribute to --errorlist [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Dec 15, 2024
1 parent 35a8a4e commit 34d462a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ class CPPCHECKLIB Tokenizer {
void checkConfiguration() const;
void macroWithSemicolonError(const Token *tok, const std::string &macroName) const;

void invalidConstFunctionTypeError(const Token *tok) const;

/**
* Is there C++ code in C file?
*/
Expand Down Expand Up @@ -628,6 +630,8 @@ class CPPCHECKLIB Tokenizer {
void setDirectives(std::list<Directive> 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);
Expand Down

0 comments on commit 34d462a

Please sign in to comment.