variable declarations: don't simplify when declaring and assigning array in the same statement

This commit is contained in:
Daniel Marjamäki 2009-02-28 20:40:37 +00:00
parent c3bbd603c0
commit 4e465f7073
2 changed files with 8 additions and 2 deletions

View File

@ -1031,13 +1031,13 @@ void Tokenizer::simplifyTokenList()
}
}
else if (Token::Match(type0, "%type% %var% [ %num% ] ,|="))
else if (Token::Match(type0, "%type% %var% [ %num% ] ,"))
{
tok2 = type0->tokAt(5); // The ',' token
typelen = 1;
}
else if (Token::Match(type0, "%type% * %var% [ %num% ] ,|="))
else if (Token::Match(type0, "%type% * %var% [ %num% ] ,"))
{
tok2 = type0->tokAt(6); // The ',' token
typelen = 1;

View File

@ -64,6 +64,7 @@ private:
TEST_CASE(redundant_plus);
TEST_CASE(parantheses1);
TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )"
TEST_CASE(declareVar);
TEST_CASE(elseif1);
@ -321,6 +322,11 @@ private:
ASSERT_EQUALS("cast < char * > ( p ) ", tok("cast<char *>(p)"));
}
void declareVar()
{
const char code[] = "void f ( ) { char str [ 100 ] = \"100\" ; } ";
ASSERT_EQUALS(code, tok(code));
}
std::string elseif(const char code[])
{