Bug 3801 – CTFE: this.arr[i] cannot be evaluated at compile time for structs

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-02-14T07:45:00Z
Last change time
2015-06-09T01:27:38Z
Keywords
rejects-valid
Assigned to
nobody
Creator
sludwig
See also
http://d.puremagic.com/issues/show_bug.cgi?id=3984

Comments

Comment #0 by sludwig — 2010-02-14T07:45:33Z
A static array contained inside a struct is not accessible during CTFE. Because of this, it seems impossible (since some versions) to define compile-time constants of such structures (for example tuple vectors or matrices). --- struct S { int arr[1]; this(int x){ arr[0] = x; // (this.arr[0u]) = x cannot be evaluated at compile time } } immutable S s_constant = S(1); // Error: cannot evaluate __ctmp1.this(1) at compile time ---
Comment #1 by clugdbug — 2010-02-26T07:37:38Z
a.b[i]=c; isn't implemented in CTFE yet, but a.b=c; is, so I'm downgrading from blocker. (It's still high priority, though). Workaround: struct S { int arr[1]; this(int x){ int[1] z = x; arr = z; } }
Comment #2 by sludwig — 2010-02-27T03:44:47Z
Unfortunately, the workaround also errors out with (although I did not check a current svn build): test.d(6): Error: this.arr[] = cast(const(int[]))x cannot be evaluated at compile time But this gave me finally another idea, which seems to work: struct test { int[1] f; this(int x){ int[] dst = f; dst[0] = x; } } [Now off to some code porting and finally trying out the recent features... ;-)]
Comment #3 by sludwig — 2010-03-18T23:46:33Z
Unfortunately, the workaround also does not work (compiles but generates incorrect code): http://d.puremagic.com/issues/show_bug.cgi?id=3984.
Comment #4 by clugdbug — 2010-03-24T12:06:16Z
Yeah, there doesn't seem to be any workaround. Changing it back to blocker.
Comment #5 by clugdbug — 2011-04-08T21:16:50Z