Fixed #3585 (errors not recognized when class has extra specification)

This commit is contained in:
Daniel Marjamäki 2013-03-18 19:09:04 +01:00
parent d9f7042992
commit 1b18bfc93c
3 changed files with 41 additions and 0 deletions

View File

@ -1734,6 +1734,15 @@ bool Tokenizer::tokenize(std::istream &code,
tok = tok->next(); 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 // catch bad typedef canonicalization
// //
// to reproduce bad typedef, download upx-ucl from: // 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 + "'."); "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 void Tokenizer::cppcheckError(const Token *tok) const
{ {
reportError(tok, Severity::error, "cppcheckError", reportError(tok, Severity::error, "cppcheckError",

View File

@ -560,6 +560,9 @@ public:
/** Syntax error. Example: invalid number of ')' */ /** Syntax error. Example: invalid number of ')' */
void syntaxError(const Token *tok, char c) const; 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 * assert that tokens are ok - used during debugging for example
* to catch problems in simplifyTokenList. * to catch problems in simplifyTokenList.

View File

@ -67,6 +67,7 @@ private:
TEST_CASE(wrong_syntax3); // #3544 TEST_CASE(wrong_syntax3); // #3544
TEST_CASE(wrong_syntax4); // #3618 TEST_CASE(wrong_syntax4); // #3618
TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO() 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(syntax_case_default);
TEST_CASE(garbageCode1); TEST_CASE(garbageCode1);
TEST_CASE(garbageCode2); // #4300 TEST_CASE(garbageCode2); // #4300
@ -771,6 +772,22 @@ private:
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); 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() { void syntax_case_default() {
//correct syntax //correct syntax
{ {