ctfe: .idup on static array and static variables

Don nospam at nospam.com
Mon Dec 14 02:02:28 PST 2009


Lutger wrote:
> i have two question related to ctfe:
> 
> 1) returning .idup on local static arrays fail but I don't understand why 
> that should be: 
> 
> string foo()
> {
>     char[1] d;
>     d[0] = 'd';
>     return d.idup;
> }
> 
> pragma(msg, foo()); // "Error: cannot evaluate foo() at compile time"
> 
> 
> .idup is not mentioned in the section on ctfe in the specs. Should this be 
> filed as a bug, enhancement request or is it my error?

Bug.


> 2) the spec says "expressions in the function may not reference any local 
> static variables". However, immutable local static variables do seem to 
> work, like this silly example:
> 
> 
> string getDigit(int digit)
> {
>     static immutable(char[10]) digits = "0123456789";
>     string result;
>     result ~= digits[digit];
>     return result;
> }



> 
> static assert( getDigit(0) == "0" );
> 
> 
> Is this ok? 

Yes, that's OK. The spec should probably say it
"may not reference any local mutable static variables."

> 
> 
> 


More information about the Digitalmars-d-learn mailing list