Fixed #1828 (### Internal error in Cppcheck. Please report it.)
This commit is contained in:
parent
b4d55d8e65
commit
f69109fbf6
|
@ -1660,6 +1660,18 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
|||
return false;
|
||||
}
|
||||
|
||||
// check for simple syntax errors..
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::simpleMatch(tok, "> struct {") &&
|
||||
Token::simpleMatch(tok->tokAt(2)->link(), "} ;"))
|
||||
{
|
||||
syntaxError(tok);
|
||||
deallocateTokens();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// specify array size..
|
||||
arraySize();
|
||||
|
||||
|
@ -6899,7 +6911,26 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const std::string &
|
|||
return NULL;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// Error message for bad iterator usage..
|
||||
|
||||
void Tokenizer::syntaxError(const Token *tok)
|
||||
{
|
||||
if (tok)
|
||||
{
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
loc.line = tok->linenr();
|
||||
loc.setfile(file(tok));
|
||||
locationList.push_back(loc);
|
||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||
Severity::error,
|
||||
"syntax error",
|
||||
"syntaxError");
|
||||
if (_errorLogger)
|
||||
_errorLogger->reportErr(errmsg);
|
||||
else
|
||||
Check::reportError(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
void Tokenizer::syntaxError(const Token *tok, char c)
|
||||
{
|
||||
|
|
|
@ -411,6 +411,10 @@ public:
|
|||
*/
|
||||
bool createLinks();
|
||||
|
||||
/** Syntax error */
|
||||
void syntaxError(const Token *tok);
|
||||
|
||||
/** Syntax error. Example: invalid number of ')' */
|
||||
void syntaxError(const Token *tok, char c);
|
||||
|
||||
/**
|
||||
|
|
|
@ -248,7 +248,7 @@ private:
|
|||
std::string tokenizeAndStringify(const char code[], bool simplify = false)
|
||||
{
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
Tokenizer tokenizer(0, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
if (simplify)
|
||||
|
@ -348,10 +348,19 @@ private:
|
|||
|
||||
void wrong_syntax()
|
||||
{
|
||||
errout.str("");
|
||||
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
||||
ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", tokenizeAndStringify(code.c_str(), true));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
{
|
||||
errout.str("");
|
||||
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
||||
ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", tokenizeAndStringify(code.c_str(), true));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
{
|
||||
errout.str("");
|
||||
const std::string code("struct A { template<int> struct { }; };");
|
||||
ASSERT_EQUALS("", tokenizeAndStringify(code.c_str(), true));
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
void minus()
|
||||
|
|
Loading…
Reference in New Issue