Fixed #2426 (### Internal error in Cppcheck. Please report it.)

This commit is contained in:
Robert Reif 2011-01-07 08:02:47 +01:00 committed by Daniel Marjamäki
parent 56ffde402f
commit bfc95e01c1
2 changed files with 28 additions and 2 deletions

View File

@ -665,8 +665,16 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
std::ostringstream str;
const Token *tok1 = tok;
while (tok && tok->str() != ";")
int level = 0;
while (tok)
{
if (level == 0 && tok->str() == ";")
break;
else if (tok->str() == "{")
level++;
else if (tok->str() == "}")
level--;
if (tok != tok1)
str << " ";
str << tok->str();
@ -694,10 +702,19 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
Token * Tokenizer::deleteInvalidTypedef(Token *typeDef)
{
Token *tok = NULL;
int level = 0;
// remove typedef but leave ;
while (typeDef->next() && typeDef->next()->str() != ";")
while (typeDef->next())
{
if (level == 0 && typeDef->next()->str() == ";")
break;
else if (typeDef->next()->str() == "{")
level++;
else if (typeDef->next()->str() == "}")
level--;
typeDef->deleteNext();
}
if (typeDef != _tokens)
{

View File

@ -232,6 +232,7 @@ private:
TEST_CASE(simplifyTypedef72); // ticket #2375
TEST_CASE(simplifyTypedef73); // ticket #2412
TEST_CASE(simplifyTypedef74); // ticket #2414
TEST_CASE(simplifyTypedef75); // ticket #2426
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4786,6 +4787,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef75() // ticket #2426
{
const char code[] = "typedef _Packed struct S { long l; }; \n";
const std::string expected = ";";
ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1()
{
{