Fix ticket 3140 and 3137 (Improve Tokenizer: Remove dead for loop - simplify while(0) better.

Note: it doesn't remove dead code if there's a label inside. Will be improved in another ticket.
This commit is contained in:
Edoardo Prezioso 2011-10-13 12:53:20 +02:00
parent 16506f0a8c
commit b792efb761
2 changed files with 3 additions and 1 deletions

View File

@ -10036,7 +10036,7 @@ void Tokenizer::simplifyWhile0()
if (Token::simpleMatch(tok->next()->link(), ") {"))
{
const Token *end = tok->next()->link()->next()->link();
if (!findmatch(tok, end, "continue|break"))
if (!findmatch(tok, end, "%var% : ;"))
{
Token::eraseTokens(tok, end ? end->next() : 0);
tok->deleteThis(); // delete "while"

View File

@ -6432,6 +6432,8 @@ private:
// for (condition is always false)
ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { int i; for (i = 0; i < 0; i++) { a; } }"));
//ticket #3140
ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { int i; for (i = 0; i < 0; i++) { foo(); break; } }"));
ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { int i; for (i = 0; i < 0; i++) { foo(); continue; } }"));
ASSERT_EQUALS("void f ( ) { }", tok("void f() { for (int i = 0; i < 0; i++) { a; } }"));
ASSERT_EQUALS("void f ( ) { }", tok("void f() { for (unsigned int i = 0; i < 0; i++) { a; } }"));
ASSERT_EQUALS("void f ( ) { }", tok("void f() { for (long long i = 0; i < 0; i++) { a; } }"));