Fixed #8896 (Tokenizer: Anonymous struct)
This commit is contained in:
parent
a1c275436f
commit
f26549e5ab
|
@ -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++));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ;";
|
||||
|
|
Loading…
Reference in New Issue