Fixed #2082 (Tokenizer::simplifyTypedef: wrong handling of array)

This commit is contained in:
Robert Reif 2010-10-13 20:02:37 +02:00 committed by Daniel Marjamäki
parent 229604b3e3
commit 267d1f273e
2 changed files with 38 additions and 15 deletions

View File

@ -1594,28 +1594,33 @@ void Tokenizer::simplifyTypedef()
if (arrayStart && arrayEnd)
{
tok2 = tok2->next();
Token * nextArrTok;
std::stack<Token *> arrLinks;
for (nextArrTok = arrayStart; nextArrTok != arrayEnd->next(); nextArrTok = nextArrTok->next())
do
{
tok2->insertToken(nextArrTok->strAt(0));
tok2 = tok2->next();
// Check for links and fix them up
if (tok2->str() == "(" || tok2->str() == "[")
arrLinks.push(tok2);
if (tok2->str() == ")" || tok2->str() == "]")
Token * nextArrTok;
std::stack<Token *> arrLinks;
for (nextArrTok = arrayStart; nextArrTok != arrayEnd->next(); nextArrTok = nextArrTok->next())
{
Token * link = arrLinks.top();
tok2->insertToken(nextArrTok->strAt(0));
tok2 = tok2->next();
tok2->link(link);
link->link(tok2);
// Check for links and fix them up
if (tok2->str() == "(" || tok2->str() == "[")
arrLinks.push(tok2);
if (tok2->str() == ")" || tok2->str() == "]")
{
Token * link = arrLinks.top();
arrLinks.pop();
tok2->link(link);
link->link(tok2);
arrLinks.pop();
}
}
tok2 = tok2->next();
}
tok2 = tok2->next();
while (Token::Match(tok2, ", %var% ;|'"));
}
simplifyType = false;

View File

@ -217,6 +217,7 @@ private:
TEST_CASE(simplifyTypedef59); // ticket #2011
TEST_CASE(simplifyTypedef60); // ticket #2035
TEST_CASE(simplifyTypedef61); // ticket #2074 and 2075
TEST_CASE(simplifyTypedef62); // ticket #2082
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4475,6 +4476,23 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef62() // ticket #2082
{
const char code[] = "typedef char TString[256];\n"
"void f()\n"
"{\n"
" TString a, b;\n"
"}";
// The expected tokens..
const std::string expected("; void f ( ) { char a [ 256 ] ; char b [ 256 ] ; }");
ASSERT_EQUALS(expected, sizeof_(code, false));
// Check for output..
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1()
{
{