D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4078 - [CTFE] Failed return of dynamic array item
Summary: [CTFE] Failed return of dynamic 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-10 16:41 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-10 16:41:23 UTC
int foo() {
    int[] arr = new int[1];
    return arr[0];
}
static assert(foo() == 0);
void main() {}


dmd 2.043 prints:

test1.d(5): Error: static assert  (null == 0) is not evaluatable at compile time
Comment 1 Don 2010-05-22 06:56:04 UTC
This patch also fixes bug 4052 which has the same root cause.

PATCH (svn 497): interpret.c, NewExp::interpret, line 1579.

       return createBlockDuplicatedArrayLiteral(newtype,
-           newtype->defaultInitLiteral(), lenExpr->toInteger()); 
+            ((TypeArray *)newtype)->next->defaultInitLiteral(),
+            lenExpr->toInteger());

TEST CASES FOR TEST SUITE:

int bug4078() {
    int[] arr = new int[1];
    return arr[0];
}
static assert(bug4078() == 0);

int bug4052() {
    int[] arr = new int[1];
    int s;
    foreach (x; arr)
        s += x;
    foreach (x; arr)
        s += x * x;
    return 4052;
}
static assert(bug4052() == 4052);
Comment 2 Walter Bright 2010-05-30 16:30:17 UTC
http://www.dsource.org/projects/dmd/changeset/507