Fix #11359 FP constStatement for function-local struct definition+initialization statement (#4561)

This commit is contained in:
chrchr-github 2022-10-22 00:27:19 +02:00 committed by GitHub
parent 1da37461e3
commit 515369739c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -8022,8 +8022,13 @@ void Tokenizer::simplifyStructDecl()
if (tok && (tok->next()->str() == "(" || tok->next()->str() == "{")) { if (tok && (tok->next()->str() == "(" || tok->next()->str() == "{")) {
tok->insertToken("="); tok->insertToken("=");
tok = tok->next(); 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() == "{") { if (tok->next()->str() == "{") {
tok->next()->str("("); tok->next()->str("(");
tok->linkAt(1)->str(")"); tok->linkAt(1)->str(")");

View File

@ -418,6 +418,13 @@ private:
" (*this)[0] << a, b, c;\n" " (*this)[0] << a, b, c;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); 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 // #8451

View File

@ -1270,10 +1270,10 @@ private:
void simplifyStructDecl8() { 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 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("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 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("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("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 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};")); ASSERT_EQUALS("enum H : short { x , y , z } ; enum H h ; h = x ;", tok("enum H : short { x, y, z } h{x};"));