D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4052 - [CTFE] increment from array item
Summary: [CTFE] increment from array item
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2010-04-02 14:49 UTC by bearophile_hugs
Modified: 2015-06-09 05:13 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-04-02 14:49:25 UTC
(Not tested with the latest bug fixes, so this can be already fixed)


int foo() {
    int[] arr = new int[1];
    int s;
    foreach (x; arr)
        s += x;
    foreach (x; arr)
        s += x * x;
    return 0;
}
enum int _ = foo();
void main() {}


dmd 2.042 gives:

Error: Integer constant expression expected instead of null
test.d(10): Error: cannot evaluate foo() at compile time
test.d(10): Error: cannot evaluate foo() at compile time
Comment 1 Don 2010-05-22 06:56:44 UTC
The patch to bug 4078 fixes this.
Comment 2 Walter Bright 2010-05-30 16:30:37 UTC
http://www.dsource.org/projects/dmd/changeset/507