Fix Bugzilla Issue 24534 : goto can skip declarations in labeled statements without error

This commit is contained in:
Ben Jones 2024-05-17 13:55:59 -06:00
parent c98e69e19c
commit 7f30b66d3d
2 changed files with 30 additions and 0 deletions

View file

@ -3542,6 +3542,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
ls2.statement = ls;
sc = sc.push();
sc.lastVar = sc.enclosing.lastVar;
sc.scopesym = sc.enclosing.scopesym;
sc.ctorflow.orCSX(CSX.label);
@ -3549,6 +3550,10 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
sc.slabel = ls;
if (ls.statement)
ls.statement = ls.statement.statementSemantic(sc);
//issue 24534: lastVar may have been updated in the nested scope
sc.enclosing.lastVar = sc.lastVar;
sc.pop();
result = ls;

View file

@ -0,0 +1,25 @@
/*
TEST_OUTPUT:
---
fail_compilation/issue24534.d(12): Error: `goto` skips declaration of variable `issue24534.f1.y1`
fail_compilation/issue24534.d(13): declared here
fail_compilation/issue24534.d(20): Error: `goto` skips declaration of variable `issue24534.f2.y2`
fail_compilation/issue24534.d(22): declared here
---
*/
void f1(){ //always failed with error about skipping a declaration
int x1;
goto Label1;
int y1;
Label1:
int z1;
}
void f2(){ //compiled fine before this bug was fixed
int x2;
goto Label2;
Dummy2:
int y2;
Label2:
int z2;
}