Why it doesn't compile in D 2.0?

Don nospam at nospam.com
Sat Jan 16 22:56:44 PST 2010


aarti_pl wrote:
> W dniu 2010-01-16 15:30, Lutger pisze:
>>
>> Perhaps this is or should be a bug. You can override dup to work in ctfe:
>>
>> char[] dup(string str)
>> {
>> return str.dup;
>> }
>>
>> class Test {
>> string t1 = "test"; //Ok!
>> char[] t2 = "test".dup; //Compile error
>> char[] t3 = "test".dup(); //Ok!
>> }
>>
>> The spec even mentions it under ctfe:
>>
>> 6. as a special case, the following properties can be executed at
>> compile time:
>> ..dup
>> ..length
>> ..keys
>> ..values
>>
>> http://www.digitalmars.com/d/2.0/function.html
>>
> 
> Thanks! I will use function dup() as a workaround for now, and will put 
> bug to bugzilla.
> 
> I still wonder what has CTFE to do with this case. Do you know?
> 
> I am asking because it's not possible in general case to initialize all 
> variables in classes/structs and in global namespace.
> E.g. I had to use:
> 
> Serializer!(TextArchive) serializer;
> static this() {
>     serializer = new typeof(serializer);
> }
> 
> to initialize serializer. I am wondering if with better CTFE we could 
> get it working?
> 
> BR
> Marcin Kuszczak
> (aarti_pl)

The next DMD release will have *major* CTFE improvements. I believe this 
will work in the next release. (D1 couldn't compile it before, it can 
now; I think D2 will be the same).


More information about the Digitalmars-d-learn mailing list