Fixed ticket #3140 (Improve Tokenizer: Remove dead for loop 'for (int i = 0; i < 0; ++i)')
This commit is contained in:
parent
5f9b916dcc
commit
af23a9dcbb
|
@ -10001,10 +10001,11 @@ void Tokenizer::simplifyWhile0()
|
|||
// while (0)
|
||||
const bool while0(Token::Match(tok, "while ( 0|false )"));
|
||||
|
||||
// for (0)
|
||||
const bool for0(Token::Match(tok, "for ( %var% = %num% ; %var% < %num% ;") &&
|
||||
tok->strAt(2) == tok->strAt(6) &&
|
||||
tok->strAt(4) == tok->strAt(8));
|
||||
// for (0) - not banal, ticket #3140
|
||||
const bool for0((Token::Match(tok, "for ( %var% = %num% ; %var% < %num% ;") &&
|
||||
tok->strAt(2) == tok->strAt(6) && tok->strAt(4) == tok->strAt(8)) ||
|
||||
(Token::Match(tok->tokAt(2), "%type% %var% = %num% ; %var% < %num% ;") &&
|
||||
tok->strAt(3) == tok->strAt(7) && tok->strAt(5) == tok->strAt(9)));
|
||||
|
||||
if (!while0 && !for0)
|
||||
continue;
|
||||
|
|
|
@ -294,6 +294,8 @@ private:
|
|||
|
||||
// simplify "while (0)"
|
||||
TEST_CASE(while0);
|
||||
// ticket #3140
|
||||
TEST_CASE(while0for);
|
||||
TEST_CASE(while1);
|
||||
|
||||
TEST_CASE(enum1);
|
||||
|
@ -6344,9 +6346,17 @@ private:
|
|||
ASSERT_EQUALS("; do { continue ; } while ( false ) ;", tok("; do { continue ; } while (0);"));
|
||||
ASSERT_EQUALS("; do { break ; } while ( false ) ;", tok("; do { break; } while (0);"));
|
||||
ASSERT_EQUALS(";", tok("; while (false) { a; }"));
|
||||
}
|
||||
|
||||
void while0for()
|
||||
{
|
||||
// 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() { 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; } }"));
|
||||
ASSERT_EQUALS("void f ( ) { }", tok("void f() { for (signed long long i = 0; i < 0; i++) { a; } }"));
|
||||
}
|
||||
|
||||
void while1()
|
||||
|
|
Loading…
Reference in New Issue