Tokenizer: Skip debug warnings in Tokenizer::simplifyKnownVariables for loop variable

This commit is contained in:
Daniel Marjamäki 2010-11-13 16:40:04 +01:00
parent 5e93281310
commit 667cc8f6e5
2 changed files with 23 additions and 3 deletions

View File

@ -5918,10 +5918,15 @@ bool Tokenizer::simplifyKnownVariables()
if (varid == 0)
continue;
if (Token::Match(tok2->tokAt(-3), "for ( %type% %var% = %num% ;"))
// skip loop variable
if (Token::Match(tok2->tokAt(-2), "(|:: %type%"))
{
// skip loop variable
continue;
const Token *tok3 = tok2->previous();
while (Token::Match(tok3->previous(), ":: %type%"))
tok3 = tok3->tokAt(-2);
if (Token::Match(tok3->tokAt(-2), "for ( %type%"))
continue;
}
if (tok2->str() == tok2->strAt(2))

View File

@ -126,6 +126,7 @@ private:
TEST_CASE(simplifyKnownVariablesBailOutAssign);
TEST_CASE(simplifyKnownVariablesBailOutFor1);
TEST_CASE(simplifyKnownVariablesBailOutFor2);
TEST_CASE(simplifyKnownVariablesBailOutFor3);
TEST_CASE(simplifyKnownVariablesBailOutMemberFunction);
TEST_CASE(varid1);
@ -1916,6 +1917,20 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutFor3()
{
const char code[] = "void foo() {\n"
" for (std::string::size_type pos = 0; pos < 10; ++pos)\n"
" { }\n"
"}\n";
const char expected[] = "void foo ( ) {\n"
"for ( std :: string :: size_type pos = 0 ; pos < 10 ; ++ pos )\n"
"{ }\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
ASSERT_EQUALS("", errout.str()); // debug warnings
}
void simplifyKnownVariablesBailOutMemberFunction()
{
const char code[] = "void foo(obj a) {\n"