diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4f698ded9..2d88be060 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8741,7 +8741,7 @@ 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(), "} *|&| %type% ,|;|[|(|{|=")) { tok->insertToken("Anonymous" + MathLib::toString(count++)); } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 252e31e60..3354698d5 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3260,6 +3260,7 @@ private: ASSERT_EQUALS("enum Anonymous0 { x , y , z } ; enum Anonymous0 d ; d = x ;", tok("enum { x, y, z } d(x);", false)); ASSERT_EQUALS("enum Anonymous0 { x , y , z } ; enum Anonymous0 e ; e = x ;", tok("enum { x, y, z } e{x};", false)); ASSERT_EQUALS("struct Anonymous0 { int i ; } ; struct Anonymous0 f ; f = { 0 } ;", tok("struct { int i; } f{0};", false)); + ASSERT_EQUALS("struct Anonymous0 { } ; struct Anonymous0 x ; x = { 0 } ;", tok("struct {} x = {0};", false)); ASSERT_EQUALS("enum G : short { x , y , z } ; enum G g ; g = x ;", tok("enum G : short { x, y, z } g(x);", false)); ASSERT_EQUALS("enum H : short { x , y , z } ; enum H h ; h = x ;", tok("enum H : short { x, y, z } h{x};", false)); ASSERT_EQUALS("enum class I : short { x , y , z } ; enum I i ; i = x ;", tok("enum class I : short { x, y, z } i(x);", false));