On Friday, 11 July 2014 at 21:02:30 UTC, Timon Gehr wrote:
He is allocating an immutable(int)[] here. There is no reason why it should allocate unless providing different addresses for different runs of the code is considered a feature, as the literal has a compile-time known value. It's just that the frontend does not actually elide the allocation, and this would be a valid extension to ask for.

In any case, the allocation can be manually elided as follows:

void main(string[] args)@nogc{
    auto s1 = "hello";
    static immutable _a1 = [1, 2];
    auto a1 = _a1;
}

(Not actually tested, because I am having trouble downloading the beta for some reason.)

Sure, no objections here - it just happened that doing so for string literals was more obvious because literals themselves are immutable. And doing so for arrays requires tiny bit of semantical analysis (probably not really difficult too, I don't know)

Reply via email to