Skip to content

Commit 11aef93

Browse files
authored
fixed #13420 - Tokenizer did not contribute to --errorlist (#7107)
1 parent 7dc579a commit 11aef93

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

lib/cppcheck.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
18931893

18941894
CheckUnusedFunctions::getErrorMessages(errorlogger);
18951895
Preprocessor::getErrorMessages(errorlogger, s);
1896+
Tokenizer::getErrorMessages(errorlogger, s);
18961897
}
18971898

18981899
void CppCheck::analyseClangTidy(const FileSettings &fileSettings)

lib/tokenize.cpp

+25-8
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,7 @@ void Tokenizer::simplifyTypedef()
11261126
if (!ts.fail() && numberOfTypedefs[ts.name()] == 1 &&
11271127
(numberOfTypedefs.find(ts.getTypedefToken()->strAt(1)) == numberOfTypedefs.end() || ts.getTypedefToken()->strAt(2) == "(")) {
11281128
if (mSettings.severity.isEnabled(Severity::portability) && ts.isInvalidConstFunctionType(typedefs))
1129-
reportError(tok->next(), Severity::portability, "invalidConstFunctionType",
1130-
"It is unspecified behavior to const qualify a function type.");
1129+
invalidConstFunctionTypeError(tok->next());
11311130
typedefs.emplace(ts.name(), ts);
11321131
if (!ts.isStructEtc())
11331132
tok = ts.endToken();
@@ -5743,7 +5742,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
57435742
if (isCPP() && mSettings.severity.isEnabled(Severity::information)) {
57445743
for (const Token *tok = list.front(); tok; tok = tok->next()) {
57455744
if (Token::Match(tok, "class %type% %type% [:{]")) {
5746-
unhandled_macro_class_x_y(tok);
5745+
unhandled_macro_class_x_y(tok, tok->str(), tok->strAt(1), tok->strAt(2), tok->strAt(3));
57475746
}
57485747
}
57495748
}
@@ -8114,16 +8113,16 @@ void Tokenizer::unknownMacroError(const Token *tok1) const
81148113
throw InternalError(tok1, "There is an unknown macro here somewhere. Configuration is required. If " + tok1->str() + " is a macro then please configure it.", InternalError::UNKNOWN_MACRO);
81158114
}
81168115

8117-
void Tokenizer::unhandled_macro_class_x_y(const Token *tok) const
8116+
void Tokenizer::unhandled_macro_class_x_y(const Token *tok, const std::string& type, const std::string& x, const std::string& y, const std::string& bracket) const
81188117
{
81198118
reportError(tok,
81208119
Severity::information,
81218120
"class_X_Y",
81228121
"The code '" +
8123-
tok->str() + " " +
8124-
tok->strAt(1) + " " +
8125-
tok->strAt(2) + " " +
8126-
tok->strAt(3) + "' is not handled. You can use -I or --include to add handling of this code.");
8122+
type + " " +
8123+
x + " " +
8124+
y + " " +
8125+
bracket + "' is not handled. You can use -I or --include to add handling of this code.");
81278126
}
81288127

81298128
void Tokenizer::macroWithSemicolonError(const Token *tok, const std::string &macroName) const
@@ -8134,6 +8133,14 @@ void Tokenizer::macroWithSemicolonError(const Token *tok, const std::string &mac
81348133
"Ensure that '" + macroName + "' is defined either using -I, --include or -D.");
81358134
}
81368135

8136+
void Tokenizer::invalidConstFunctionTypeError(const Token *tok) const
8137+
{
8138+
reportError(tok,
8139+
Severity::portability,
8140+
"invalidConstFunctionType",
8141+
"It is unspecified behavior to const qualify a function type.");
8142+
}
8143+
81378144
void Tokenizer::cppcheckError(const Token *tok) const
81388145
{
81398146
printDebugOutput(0, std::cout);
@@ -10908,3 +10915,13 @@ bool Tokenizer::isPacked(const Token * bodyStart) const
1090810915
return d.linenr < bodyStart->linenr() && d.str == "#pragma pack(1)" && d.file == list.getFiles().front();
1090910916
});
1091010917
}
10918+
10919+
void Tokenizer::getErrorMessages(ErrorLogger& errorLogger, const Settings& settings)
10920+
{
10921+
Tokenizer tokenizer(settings, errorLogger);
10922+
tokenizer.invalidConstFunctionTypeError(nullptr);
10923+
// checkLibraryNoReturn
10924+
tokenizer.unhandled_macro_class_x_y(nullptr, emptyString, emptyString, emptyString, emptyString);
10925+
tokenizer.macroWithSemicolonError(nullptr, emptyString);
10926+
tokenizer.unhandledCharLiteral(nullptr, emptyString);
10927+
}

lib/tokenize.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,14 @@ class CPPCHECKLIB Tokenizer {
390390
private:
391391

392392
/** Report that there is an unhandled "class x y {" code */
393-
void unhandled_macro_class_x_y(const Token *tok) const;
393+
void unhandled_macro_class_x_y(const Token *tok, const std::string& type, const std::string& x, const std::string& y, const std::string& bracket) const;
394394

395395
/** Check configuration (unknown macros etc) */
396396
void checkConfiguration() const;
397397
void macroWithSemicolonError(const Token *tok, const std::string &macroName) const;
398398

399+
void invalidConstFunctionTypeError(const Token *tok) const;
400+
399401
/**
400402
* Is there C++ code in C file?
401403
*/
@@ -628,6 +630,8 @@ class CPPCHECKLIB Tokenizer {
628630
void setDirectives(std::list<Directive> directives);
629631

630632
std::string dumpTypedefInfo() const;
633+
634+
static void getErrorMessages(ErrorLogger& errorLogger, const Settings& settings);
631635
private:
632636
const Token *processFunc(const Token *tok2, bool inOperator) const;
633637
Token *processFunc(Token *tok2, bool inOperator);

0 commit comments

Comments
 (0)