Why it doesn't compile in D 2.0?

aarti_pl aarti at interia.pl
Sun Jan 17 11:20:17 PST 2010


W dniu 2010-01-17 19:38, Don pisze:
> aarti_pl wrote:
>>
>> class Test {
>> string t1 = "test"; //Ok!
>> char[] t2 = "test".dup; //Compile error
>> }
>>
>> void main(char[][] args) {
>> }
>>
>> Error:
>> hello.d(3): Error: cannot evaluate _adDupT((&
>> D12TypeInfo_Aya6__initZ),"test") at compile time
>> hello.d(3): Error: cannot evaluate _adDupT((&
>> D12TypeInfo_Aya6__initZ),"test") at compile time
>>
>> Is there workaround?
>>
>> BR
>> Marcin Kuszczak
>> (aarti_pl)
>
> Workaround: It works in dmd2, svn 337 and later <g>.

Wow. I even could not report it as a bug. That is really fast bug fixing :-)

Could you please explain what has initialization of variables to do with 
CTFE? As far as I understand it should be done on runtime... So why is 
there compile time execution involved?

And other questions. Would it be possible to initialize more complex 
types with better CTFE? I see it as quite major issue when I can not 
write in class definition or in global scope:

auto serializer = new Serializer!(TextArchive)();

BR
Marcin Kuszczak
(aarti_pl)


More information about the Digitalmars-d-learn mailing list