fix Issue 22933 - importC: goto skips declaration of variable (#13913)

This commit is contained in:
Walter Bright 2022-03-29 12:26:44 -07:00 committed by GitHub
parent aea95087f8
commit 9aa405e445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View file

@ -1230,7 +1230,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
} }
// Fix up forward-referenced gotos // Fix up forward-referenced gotos
if (funcdecl.gotos) if (funcdecl.gotos && !funcdecl.isCsymbol())
{ {
for (size_t i = 0; i < funcdecl.gotos.dim; ++i) for (size_t i = 0; i < funcdecl.gotos.dim; ++i)
{ {

View file

@ -1761,6 +1761,9 @@ extern (C++) final class GotoStatement : Statement
return new GotoStatement(loc, ident); return new GotoStatement(loc, ident);
} }
/**************
* Returns: true for error
*/
extern (D) bool checkLabel() extern (D) bool checkLabel()
{ {
if (!label.statement) if (!label.statement)

View file

@ -2369,7 +2369,7 @@ package (dmd) extern (C++) final class StatementSemanticVisitor : Visitor
ss._body = cs; ss._body = cs;
} }
if (ss.checkLabel()) if (!(sc.flags & SCOPE.Cfile) && ss.checkLabel())
{ {
sc.pop(); sc.pop();
return setError(); return setError();
@ -3844,7 +3844,7 @@ package (dmd) extern (C++) final class StatementSemanticVisitor : Visitor
fd.gotos = new GotoStatements(); fd.gotos = new GotoStatements();
fd.gotos.push(gs); fd.gotos.push(gs);
} }
else if (gs.checkLabel()) else if (!(sc.flags & SCOPE.Cfile) && gs.checkLabel())
return setError(); return setError();
result = gs; result = gs;

View file

@ -0,0 +1,9 @@
// https://issues.dlang.org/show_bug.cgi?id=22933
void fn()
{
goto L;
int x = 1;
L:
return;
}