Bug 2237 – string mixin + const array = array literal constructed upon every use (??!?!)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2008-07-19T12:37:25Z
Last change time
2019-10-10T14:54:26Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Jarrett Billingsley

Comments

Comment #0 by jarrett.billingsley — 2008-07-19T12:37:25Z
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.
Comment #1 by yebblies — 2012-02-02T01:49:34Z
*** This issue has been marked as a duplicate of issue 2356 ***
Comment #2 by verylonglogin.reg — 2012-02-09T00:26:02Z
Is it really a duplicate? issue 2356 doesn't mention string mixins or any other initializer dependencies. Why --- const int[] arr = mixin("[5, 6]"); --- behaves differ from --- mixin("const int[] arr = [5, 6];"); --- ?
Comment #3 by yebblies — 2012-02-09T07:05:57Z
Hmm, I think I must have put the wrong bug number in. I think this is a duplicate of the D1 version of bug 2414. Now if only I could find the actual bug... (I can only find that one because I know it has 'yum' in the title.) Glad somebody is checking.
Comment #4 by razvan.nitu1305 — 2019-10-10T14:54:26Z
The issue does not manifest in D2 (git master). The code generated for: const int[] arr = mixin("[5, 6]"); is identical to the one generated on for: mixin("const int[] arr = [5, 6];"); i.e. It actually puts the array in the static data segment and accesses it from there, like it should. Closing as fixed.