[Issue 2559] bad code generation for enum arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 8 00:08:26 PDT 2009


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


clugdbug at yahoo.com.au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |blocker
           Keywords|                            |accepts-invalid
           Priority|P2                          |P1
            Summary|enum doesn't work properly  |bad code generation for enum
                   |for invariant arrays        |arrays




------- Comment #1 from clugdbug at yahoo.com.au  2009-04-08 02:08 -------
I've changed the title, since I believe this bug is extremely serious.
Simpler example:
--------------
enum ubyte[4] a = [5,6,7,8];

void main()
{
  int x=3;
  assert(a[x]==7);
}
-----------
Interestingly, compiling with -O gives
bug.d(7): Error: variable a used before set

which shows that the initializer is being ignored.
My opinion is that that's correct -- the only reason you're using an enum is so
that it doesn't appear in the executable! Using a variable to index into the
enum is arguably equivalent to taking the address of the enum, and should
therefore be illegal -- use "immutable" instead.


-- 



More information about the Digitalmars-d-bugs mailing list