www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2237] New: string mixin + const array = array literal constructed upon every use (??!?!)

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

           Summary: string mixin + const array = array literal constructed
                    upon every use (??!?!)
           Product: D
           Version: 1.031
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jarrett.billingsley gmail.com


Oh, DMDFE, what am I ever going to do with you.

const int[] arr = mixin("[5, 6]");

void main()
{
        int f = 0;
        int y = arr[f]; // make sure it's a non-constant index
}

If you look at the generated code, it actually inserts the dynamic array
literal [5, 6] EVERYWHERE 'arr' IS USED.  So it's more like you do:

int y = [5, 6][f];

If you change the declaration of 'arr' to be a mixin declaration instead:

mixin("const int[] arr = [5, 6];");

It actually puts the array in the static data segment and accesses it from
there, like it should.


-- 
Jul 19 2008