Tokenizer: Skip debug warnings in Tokenizer::simplifyKnownVariables for loop variable
This commit is contained in:
parent
5e93281310
commit
667cc8f6e5
|
@ -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))
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue