Bug 5907 – CTFE: Ref assignments are noop at compile time

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-04-28T17:05:00Z
Last change time
2015-06-09T05:15:09Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-04-28T17:05:20Z
auto ok() { int[2] result; foreach (index, ref sample; result) { result[index] = 1; } return result; } auto fail() { int[2] result; foreach (index, ref sample; result) { sample = 1; } return result; } float[2] ctfe_ok = ok(); float[2] ctfe_fail = fail(); void main() { assert(ok == [1, 1]); // ok assert(fail == [1, 1]); // ok assert(ctfe_ok == [1, 1]); assert(ctfe_fail == [1, 1]); // throws } Unfortunately they fail silently and then you have bugs in your code. I'm not sure but maybe this bug was reported already? (or a fix is scheduled for the next release?) I couldn't be sure so I'm reporting it just in case.
Comment #1 by andrej.mitrovich — 2011-04-28T17:07:42Z
Oh btw sorry about using float[2] instead of int[2] there. I was quickly converting some existing code. The bug is still there if ctfe_ok and ctfe_fail are typed as ints.
Comment #2 by clugdbug — 2011-05-06T01:48:14Z
dup of 1330, which is fixed. *** This issue has been marked as a duplicate of issue 1330 ***