Fixed #8896 (Tokenizer: Anonymous struct)

This commit is contained in:
Daniel Marjamäki 2018-12-15 08:42:35 +01:00
parent a1c275436f
commit f26549e5ab
2 changed files with 8 additions and 2 deletions

View File

@ -8792,14 +8792,14 @@ void Tokenizer::simplifyStructDecl()
continue;
// check for anonymous struct/union
if (Token::Match(tok, "struct|union {")) {
if (Token::Match(tok->next()->link(), "} *|&| %type% ,|;|[|(|{|=")) {
if (Token::Match(tok->next()->link(), "} const| *|&| const| %type% ,|;|[|(|{|=")) {
tok->insertToken("Anonymous" + MathLib::toString(count++));
}
}
// check for derived anonymous class/struct
else if (cpp && Token::Match(tok, "class|struct :")) {
const Token *tok1 = Token::findsimplematch(tok, "{");
if (tok1 && Token::Match(tok1->link(), "} *|&| %type% ,|;|[|(|{")) {
if (tok1 && Token::Match(tok1->link(), "} const| *|&| const| %type% ,|;|[|(|{")) {
tok->insertToken("Anonymous" + MathLib::toString(count++));
}
}

View File

@ -2987,6 +2987,12 @@ private:
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct {int a;} const array[3] = {0};";
const char expected[] = "struct Anonymous0 { int a ; } const array [ 3 ] = { 0 } ;";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct { } abc, def;";
const char expected[] = "struct Anonymous0 { } ; struct Anonymous0 abc ; struct Anonymous0 def ;";