From 499a12c896107f931f4b0a41f2aa03c5c1d25a40 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 26 Aug 2010 20:44:13 +0200 Subject: [PATCH] Tokenizer::simplifyTypedef: Report about unhandled typedefs. Ticket: #1821 --- lib/tokenize.cpp | 36 ++++++++++++++++++++++++++++++++++++ lib/tokenize.h | 2 ++ test/testsimplifytokens.cpp | 4 ++++ 3 files changed, 42 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 44e3c59c5..966689720 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -635,6 +635,38 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) return false; } +void Tokenizer::unsupportedTypedef(const Token *tok) const +{ +#ifndef NDEBUG + std::ostringstream str; + const Token *tok1 = tok; + while (tok && tok->str() != ";") + { + if (tok != tok1) + str << " "; + str << tok->str(); + tok = tok->next(); + } + if (tok) + str << " ;"; + std::list locationList; + ErrorLogger::ErrorMessage::FileLocation loc; + loc.line = tok1->linenr(); + loc.setfile(file(tok1)); + locationList.push_back(loc); + + const ErrorLogger::ErrorMessage errmsg(locationList, + Severity::error, + "Failed to parse \'" + str.str() + "\'. The checking continues anyway.", + "cppcheckError"); + + if (_errorLogger) + _errorLogger->reportErr(errmsg); + else + Check::reportError(errmsg); +#endif +} + struct SpaceInfo { bool isNamespace; @@ -902,6 +934,8 @@ void Tokenizer::simplifyTypedef() } else { + unsupportedTypedef(typeDef); + // unhandled typedef, skip it and continue tok = tok->tokAt(offset); continue; @@ -1084,6 +1118,8 @@ void Tokenizer::simplifyTypedef() // unhandled typedef, skip it and continue else { + unsupportedTypedef(typeDef); + continue; } diff --git a/lib/tokenize.h b/lib/tokenize.h index 31c8d8f99..15cf4127f 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -502,6 +502,8 @@ public: void duplicateTypedefError(const Token *tok1, const Token *tok2, const std::string & type); void duplicateDeclarationError(const Token *tok1, const Token *tok2, const std::string &type); + void unsupportedTypedef(const Token *tok) const; + private: /** Disable copy constructor, no implementation */ Tokenizer(const Tokenizer &); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index eca7a0e77..76b35200f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -4236,7 +4236,11 @@ private: // this is invalid C so just make sure it doesn't crash checkSimplifyTypedef(code); +#ifndef NDEBUG + ASSERT_EQUALS("[test.cpp:1]: (error) Failed to parse 'typedef int ( * int ( * ) ( ) ) ( ) ;'. The checking continues anyway.\n", errout.str()); +#else ASSERT_EQUALS("", errout.str()); +#endif } {