Fixed #1580 (unnamed anonymous struct can segfault)

This commit is contained in:
Robert Reif 2010-04-08 17:40:23 +02:00 committed by Daniel Marjamäki
parent e23197a527
commit bc0a318b6d
2 changed files with 33 additions and 7 deletions

View File

@ -6925,15 +6925,23 @@ void Tokenizer::simplifyStructDecl()
tok = tok->next();
tok->insertToken(name.c_str());
}
// unnamed anonymous struct/union so remove it
else if (tok->next()->str() == ";")
{
Token *previous = tok1->previous();
previous->deleteNext();
previous->deleteNext();
tok1 = previous->next();
previous = tok->previous();
previous->deleteNext();
previous->deleteNext();
tok1->deleteThis();
if (tok1->next() == tok)
{
tok1->deleteThis();
tok = tok1;
}
else
tok1->deleteThis();
tok->deleteThis();
if (tok->next())
tok->deleteThis();
if (!tok->next())
return;
}
tok = tok1->next();

View File

@ -4357,6 +4357,24 @@ private:
const char expected[] = "struct ABC : public XYZ { struct Anonymous0 { } ; Anonymous0 def ; } ;";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct { int x; }; int y;";
const char expected[] = "int x ; int y ;";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct { int x; };";
const char expected[] = "int x ; ;";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct { };";
const char expected[] = ";";
ASSERT_EQUALS(expected, tok(code, false));
}
}
};