D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2960 - CTFE rejects static array to dynamic array casts
Summary: CTFE rejects static array to dynamic array casts
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2009-05-10 06:52 UTC by Christian Kamm
Modified: 2014-04-18 09:12 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Christian Kamm 2009-05-10 06:52:16 UTC
Test case:

char[] foo(char[] source) { return ""; }
const v = "bar";
const r = foo(v);

Result:
Error: cannot evaluate foo(cast(char[])v) at compile time

This works in D2 because of changes to Cast in constfold.c. LDC backported the changes by adding this code from the D2 frontend:

    if (e1->op == TOKstring)
    {
	if (tb->ty == Tarray && typeb->ty == Tarray &&
	    tb->nextOf()->size() == typeb->nextOf()->size())
	{
	    return expType(to, e1);
	}
    }
Comment 1 Walter Bright 2009-09-03 13:28:38 UTC
Fixed dmd 1.047