diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index be13fa6e5..5f3aa734a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8022,8 +8022,13 @@ void Tokenizer::simplifyStructDecl() if (tok && (tok->next()->str() == "(" || tok->next()->str() == "{")) { tok->insertToken("="); tok = tok->next(); + const bool isEnum = start->str() == "enum"; + if (!isEnum && cpp) { + tok->insertToken(type->str()); + tok = tok->next(); + } - if (start->str() == "enum") { + if (isEnum) { if (tok->next()->str() == "{") { tok->next()->str("("); tok->linkAt(1)->str(")"); diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 41f783ad4..7106fb7f3 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -418,6 +418,13 @@ private: " (*this)[0] << a, b, c;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" // #11359 + " struct S {\n" + " S(int x, int y) {}\n" + " } s(1, 2);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // #8451 diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index efe16cc4b..4f2f7d49b 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1270,10 +1270,10 @@ private: void simplifyStructDecl8() { ASSERT_EQUALS("enum A { x , y , z } ; enum A a ; a = x ;", tok("enum A { x, y, z } a(x);")); ASSERT_EQUALS("enum B { x , y , z } ; enum B b ; b = x ;", tok("enum B { x , y, z } b{x};")); - ASSERT_EQUALS("struct C { int i ; } ; struct C c ; c = { 0 } ;", tok("struct C { int i; } c{0};")); + ASSERT_EQUALS("struct C { int i ; } ; struct C c ; c = C { 0 } ;", tok("struct C { int i; } c{0};")); ASSERT_EQUALS("enum Anonymous0 { x , y , z } ; enum Anonymous0 d ; d = x ;", tok("enum { x, y, z } d(x);")); ASSERT_EQUALS("enum Anonymous0 { x , y , z } ; enum Anonymous0 e ; e = x ;", tok("enum { x, y, z } e{x};")); - ASSERT_EQUALS("struct Anonymous0 { int i ; } ; struct Anonymous0 f ; f = { 0 } ;", tok("struct { int i; } f{0};")); + ASSERT_EQUALS("struct Anonymous0 { int i ; } ; struct Anonymous0 f ; f = Anonymous0 { 0 } ;", tok("struct { int i; } f{0};")); ASSERT_EQUALS("struct Anonymous0 { } ; struct Anonymous0 x ; x = { 0 } ;", tok("struct {} x = {0};")); ASSERT_EQUALS("enum G : short { x , y , z } ; enum G g ; g = x ;", tok("enum G : short { x, y, z } g(x);")); ASSERT_EQUALS("enum H : short { x , y , z } ; enum H h ; h = x ;", tok("enum H : short { x, y, z } h{x};"));