Fixed #3585 (errors not recognized when class has extra specification)
This commit is contained in:
parent
d9f7042992
commit
1b18bfc93c
|
@ -1734,6 +1734,15 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
tok = tok->next();
|
||||
}
|
||||
|
||||
// class x y {
|
||||
if (_settings->isEnabled("information")) {
|
||||
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "class %type% %type% [:{]")) {
|
||||
unhandled_macro_class_x_y(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// catch bad typedef canonicalization
|
||||
//
|
||||
// to reproduce bad typedef, download upx-ucl from:
|
||||
|
@ -7846,6 +7855,18 @@ void Tokenizer::syntaxError(const Token *tok, char c) const
|
|||
"when these macros are defined: '" + _configuration + "'.");
|
||||
}
|
||||
|
||||
void Tokenizer::unhandled_macro_class_x_y(const Token *tok)
|
||||
{
|
||||
reportError(tok,
|
||||
Severity::information,
|
||||
"class_X_Y",
|
||||
"The code '" +
|
||||
tok->str() + " " +
|
||||
tok->strAt(1) + " " +
|
||||
tok->strAt(2) + " " +
|
||||
tok->strAt(3) + "' is not handled. You can use -I or --include to add handling of this code.");
|
||||
}
|
||||
|
||||
void Tokenizer::cppcheckError(const Token *tok) const
|
||||
{
|
||||
reportError(tok, Severity::error, "cppcheckError",
|
||||
|
|
|
@ -560,6 +560,9 @@ public:
|
|||
/** Syntax error. Example: invalid number of ')' */
|
||||
void syntaxError(const Token *tok, char c) const;
|
||||
|
||||
/** Report that there is an unhandled "class x y {" code */
|
||||
void unhandled_macro_class_x_y(const Token *tok);
|
||||
|
||||
/**
|
||||
* assert that tokens are ok - used during debugging for example
|
||||
* to catch problems in simplifyTokenList.
|
||||
|
|
|
@ -67,6 +67,7 @@ private:
|
|||
TEST_CASE(wrong_syntax3); // #3544
|
||||
TEST_CASE(wrong_syntax4); // #3618
|
||||
TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO()
|
||||
TEST_CASE(wrong_syntax_class_x_y); // #3585 - class x y { };
|
||||
TEST_CASE(syntax_case_default);
|
||||
TEST_CASE(garbageCode1);
|
||||
TEST_CASE(garbageCode2); // #4300
|
||||
|
@ -771,6 +772,22 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
}
|
||||
|
||||
void wrong_syntax_class_x_y() {
|
||||
// #3585
|
||||
const char code[] = "class x y { };";
|
||||
|
||||
errout.str("");
|
||||
|
||||
Settings settings;
|
||||
settings.addEnabled("information");
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.c");
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
ASSERT_EQUALS("[test.c:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code.\n", errout.str());
|
||||
}
|
||||
|
||||
void syntax_case_default() {
|
||||
//correct syntax
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue