Skip to content

Commit

Permalink
Merge pull request #5343 from JohanEngelen/fail15535
Browse files Browse the repository at this point in the history
fix Issue 15535 - Disallow "goto default" in final switches.
  • Loading branch information
yebblies committed Jan 15, 2016
2 parents 2f9effe + 3e245ec commit 8968b7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/statement.d
Expand Up @@ -4246,6 +4246,11 @@ public:
error("goto default not in switch statement");
return new ErrorStatement();
}
if (sw.isFinal)
{
error("goto default not allowed in final switch statement");
return new ErrorStatement();
}
return this;
}

Expand Down
22 changes: 22 additions & 0 deletions test/fail_compilation/fail15535.d
@@ -0,0 +1,22 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail15535.d(17): Error: goto default not allowed in final switch statement
---
*/

void test()
{
int i;
switch (i)
{
case 0:
final switch (i)
{
case 1:
goto default;
}
default:
break;
}
}

0 comments on commit 8968b7b

Please sign in to comment.