Fixed #1963 (typedef array incorrectly simplified)

This commit is contained in:
Robert Reif 2010-08-20 07:11:02 +02:00 committed by Daniel Marjamäki
parent 043ff6aab5
commit f123e951ec
2 changed files with 37 additions and 0 deletions

View File

@ -1535,6 +1535,11 @@ void Tokenizer::simplifyTypedef()
tok2 = tok2->next();
Token::createMutualLinks(tok2, tok3);
}
else if (tok2->tokAt(2) && tok2->tokAt(2)->str() == "[")
{
while (tok2->tokAt(2) && tok2->tokAt(2)->str() == "[")
tok2 = tok2->tokAt(2)->link()->previous();
}
if (arrayStart && arrayEnd)
{

View File

@ -212,6 +212,7 @@ private:
TEST_CASE(simplifyTypedef55);
TEST_CASE(simplifyTypedef56); // ticket #1829
TEST_CASE(simplifyTypedef57); // ticket #1846
TEST_CASE(simplifyTypedef58); // ticket #1963
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4333,6 +4334,37 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef58() // ticket #1963
{
{
const char code[] = "typedef int vec2_t[2];\n"
"vec2_t coords[4] = {1,2,3,4,5,6,7,8};\n";
// The expected result..
const std::string expected("; "
"int coords [ 4 ] [ 2 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ;");
ASSERT_EQUALS(expected, sizeof_(code));
// Check for output..
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "typedef int vec2_t[2];\n"
"vec2_t coords[4][5][6+1] = {1,2,3,4,5,6,7,8};\n";
// The expected result..
const std::string expected("; "
"int coords [ 4 ] [ 5 ] [ 7 ] [ 2 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ;");
ASSERT_EQUALS(expected, sizeof_(code));
// Check for output..
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
}
void simplifyTypedefFunction1()
{
{