Skip to content
Browse files

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

  • Loading branch information...
1 parent d9f7042 commit 1b18bfc93c94ea656a7f35a0673efb8535e8e538 @danmar committed
Showing with 41 additions and 0 deletions.
  1. +21 −0 lib/tokenize.cpp
  2. +3 −0 lib/tokenize.h
  3. +17 −0 test/testtokenize.cpp
View
21 lib/tokenize.cpp
@@ -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",
View
3 lib/tokenize.h
@@ -560,6 +560,9 @@ class CPPCHECKLIB Tokenizer {
/** 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.
View
17 test/testtokenize.cpp
@@ -67,6 +67,7 @@ class TestTokenizer : public TestFixture {
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 @@ class TestTokenizer : public TestFixture {
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
{

0 comments on commit 1b18bfc

Please sign in to comment.
Something went wrong with that request. Please try again.