Fixed #2110 (Tokenizer::simplifyTypedef: regression - wrong simplification of 'typedef char TString[256];')

This commit is contained in:
Daniel Marjamäki 2010-10-20 06:09:29 +02:00
parent f8c02718a5
commit 02ba2b202e
2 changed files with 59 additions and 9 deletions

View File

@ -1619,8 +1619,16 @@ void Tokenizer::simplifyTypedef()
}
tok2 = tok2->next();
if (tok2->str() == "=")
{
if (tok2->next()->str() == "{")
tok2 = tok2->next()->link()->next();
else if (tok2->next()->str().at(0) == '\"')
tok2 = tok2->next()->next();
}
}
while (Token::Match(tok2, ", %var% ;|'"));
while (Token::Match(tok2, ", %var% ;|'|="));
}
simplifyType = false;

View File

@ -4478,18 +4478,60 @@ private:
void simplifyTypedef62() // ticket #2082
{
const char code[] = "typedef char TString[256];\n"
"void f()\n"
"{\n"
" TString a, b;\n"
"}";
const char code1[] = "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));
const std::string expected1("; void f ( ) { char a [ 256 ] ; char b [ 256 ] ; }");
ASSERT_EQUALS(expected1, sizeof_(code1, false));
// Check for output..
checkSimplifyTypedef(code);
checkSimplifyTypedef(code1);
ASSERT_EQUALS("", errout.str());
const char code2[] = "typedef char TString[256];\n"
"void f()\n"
"{\n"
" TString a = { 0 }, b = { 0 };\n"
"}";
// The expected tokens..
const std::string expected2("; void f ( ) { char a [ 256 ] = { 0 } ; char b [ 256 ] = { 0 } ; }");
ASSERT_EQUALS(expected2, tok(code2, false));
// Check for output..
checkSimplifyTypedef(code2);
ASSERT_EQUALS("", errout.str());
const char code3[] = "typedef char TString[256];\n"
"void f()\n"
"{\n"
" TString a = \"\", b = \"\";\n"
"}";
// The expected tokens..
const std::string expected3("; void f ( ) { char a [ 256 ] = \"\" ; char b [ 256 ] = \"\" ; }");
ASSERT_EQUALS(expected3, tok(code3, false));
// Check for output..
checkSimplifyTypedef(code3);
ASSERT_EQUALS("", errout.str());
const char code4[] = "typedef char TString[256];\n"
"void f()\n"
"{\n"
" TString a = \"1234\", b = \"5678\";\n"
"}";
// The expected tokens..
const std::string expected4("; void f ( ) { char a [ 256 ] = \"1234\" ; char b [ 256 ] = \"5678\" ; }");
ASSERT_EQUALS(expected4, tok(code4, false));
// Check for output..
checkSimplifyTypedef(code4);
ASSERT_EQUALS("", errout.str());
}