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:
parent
16506f0a8c
commit
b792efb761
|
@ -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"
|
||||
|
|
|
@ -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; } }"));
|
||||
|
|
Loading…
Reference in New Issue