From 1b18bfc93c94ea656a7f35a0673efb8535e8e538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 18 Mar 2013 19:09:04 +0100 Subject: [PATCH] Fixed #3585 (errors not recognized when class has extra specification) --- lib/tokenize.cpp | 21 +++++++++++++++++++++ lib/tokenize.h | 3 +++ test/testtokenize.cpp | 17 +++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 26df1ccf5..d73af42b7 100644 --- a/lib/tokenize.cpp +++ b/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", diff --git a/lib/tokenize.h b/lib/tokenize.h index fce4aedfc..a4558a8ac 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -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. diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 55d86b8d0..6e3c5031e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 {