Tokenizer::simplifyTypedef: Report about unhandled typedefs. Ticket: #1821

This commit is contained in:
Robert Reif 2010-08-26 20:44:13 +02:00 committed by Daniel Marjamäki
parent 8b18aaff25
commit 499a12c896
3 changed files with 42 additions and 0 deletions

View File

@ -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<ErrorLogger::ErrorMessage::FileLocation> 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;
}

View File

@ -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 &);

View File

@ -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
}
{