Skip to content

Commit

Permalink
Issue 7358 - final switch over enum should add throwing default in de…
Browse files Browse the repository at this point in the history
…bug mode at least

Add a throwing default case when compiled with asserts on.
  • Loading branch information
yebblies committed Oct 28, 2012
1 parent 4c67f3a commit b9ad0b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/statement.c
Expand Up @@ -3272,7 +3272,7 @@ Statement *SwitchStatement::semantic(Scope *sc)
}
#endif

if (!sc->sw->sdefault && (!isFinal || needswitcherror))
if (!sc->sw->sdefault && (!isFinal || needswitcherror || global.params.useAssert))
{ hasNoDefault = 1;

if (!isFinal)
Expand Down
27 changes: 27 additions & 0 deletions test/runnable/testswitch.d
Expand Up @@ -470,6 +470,32 @@ static assert(!is(typeof(
)));


/*****************************************/

void test7358()
{
static void test7358a()
{
enum X { A = 1, B = 2 }

auto x = X.A | X.B;

final switch(x)
{
case X.A:
case X.B:
break;
}
}

bool exception;
try
test7358a();
catch (Error)
exception = true;
assert(exception);
}

/*****************************************/

int main()
Expand All @@ -493,6 +519,7 @@ int main()
test17();
test19();
test20();
test7358();

printf("Success\n");
return 0;
Expand Down

0 comments on commit b9ad0b8

Please sign in to comment.