D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3951 - [CTFE] With a fixed-size array
Summary: [CTFE] With a fixed-size array
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: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-03-13 04:55 UTC by bearophile_hugs
Modified: 2014-02-15 02:42 UTC (History)
1 user (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-03-13 04:55:46 UTC
I can't invent a good name for this bug.
This looks valid CTFE code, but it doesn't compile:


int foo1(int n)(int[n] array) {
    foreach (el; array) {}
    return 0;
}
int foo2(int n)(int[n] array) {
    for (int i; i < n; i++) {
        int el = array[i];
    }
    return 0;
}
int spam() {
    int[1] array;
    enum int i1 = foo1(array);
    enum int i2 = foo2(array);
    return 0;
}
enum int r = spam();
void main() {}



Errors produced:
test.d(12): Error: cannot cast int to int[]
test.d(12): Error: cannot cast int to int[]
test.d(12): Error: cannot cast int to int[]
test.d(13): Error: cannot evaluate foo1(array) at compile time
test.d(13): Error: cannot evaluate foo1(array) at compile time
Comment 1 Don 2010-03-26 06:58:17 UTC
This was fixed in DMD2.042.