TDPL: Manual invocation of destructor
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Aug 9 17:53:16 PDT 2010
Jonathan M Davis wrote:
> On Monday, August 09, 2010 16:40:23 Andrei Alexandrescu wrote:
>> class File {
>> FILE * fp;
>> this() { fp = fopen("/tmp/temporary"); }
>> ~this() { fclose(fp); }
>> }
>>
>> The destructor does not test fp because it assumes it was opened.
>>
>> Interestingly enough, by TDPL the code above is in fact invalid already.
>> TDPL mentions that an object's lifetime starts as soon as it's been
>> branded, which is before default construction. As a direct consequence,
>> the destructor should be able to deal with an object stamped with all
>> init values for all fields - in this case a null fp.
>
> I would take that as an argument for making clear() set the object in the state
> prior to the constructor call.
[snip]
I agree. Do others?
Andrei
More information about the Digitalmars-d
mailing list