Fixed #1580 (unnamed anonymous struct can segfault)
This commit is contained in:
parent
e23197a527
commit
bc0a318b6d
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue