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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 19 10:37:27 PDT 2008


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 at digitalmars.com
        ReportedBy: jarrett.billingsley at 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.


-- 



More information about the Digitalmars-d-bugs mailing list