diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cfca4c12d..140f690b7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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++)); } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 8a8eb31d1..dc74851b2 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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 ;";