Fixed #1985 (false positive: syntax error in try catch-block with for()-loop inside)

This commit is contained in:
Daniel Marjamäki 2010-08-26 23:19:18 +02:00
parent 02088443f9
commit 57523574ef
2 changed files with 22 additions and 0 deletions

View File

@ -1792,6 +1792,18 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
tok = tok->link();
}
// skip executing scopes (ticket #1985)..
if (Token::simpleMatch(tok, "try {"))
{
tok = tok->next()->link();
while (Token::simpleMatch(tok, "} catch ("))
{
tok = tok->tokAt(2)->link();
if (Token::simpleMatch(tok, ") {"))
tok = tok->next()->link();
}
}
// not start of statement?
if (tok->previous() && !Token::Match(tok, "[;{}]"))
continue;

View File

@ -3691,6 +3691,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
// ok code (ticket #1985)..
{
errout.str("");
std::istringstream istr("void f()\n"
"try { ;x<y; }");
Tokenizer tokenizer(0, this);
tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("", errout.str());
}
// bad code.. missing ">"
{
errout.str("");