[Issue 11051] Unmatched case in a final switch should throw in both release and non-release mode

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Sep 16 08:08:29 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11051


Maxim Fomin <maxim at maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim at maxim-fomin.ru


--- Comment #5 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-09-16 08:08:27 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> > You mean *in release mode*, right?
> 
> Right, sorry.
> 
> 
> > It currently throws in non-release mode, it doesn't throw in release mode.
> 
> This seems good to me. If you want to convert an untrusted value to an enum
> safely you should use std.conv.to:
> 
> 
> import std.stdio, std.conv;
> 
> enum E { a }
> 
> string get() {
>     //immutable e = cast(E)123;
>     immutable e = to!E(123);
>     final switch(e) {
>         case E.a: return "foobar";
>     }
> }
> void main() {
>     get.writeln;
> }

No, you will run into memory errors. Either dmd should still throw SwitchError
or insert halt instruction.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list