SAOC 2021 Projects Summarized
user1234
user1234 at 12.de
Wed Sep 1 22:23:59 UTC 2021
On Wednesday, 1 September 2021 at 18:20:59 UTC, Paul Backus wrote:
> On Monday, 30 August 2021 at 16:12:57 UTC, Adam D Ruppe wrote:
>> On Monday, 30 August 2021 at 16:03:29 UTC, Guillaume Piolat
>> wrote:
>>> Hyped by ProtoObject, this is our hope for a nothrow @nogc
>>> .destroy eventually!
>>
>> This fails today only because of the rt_finalize hook working
>> through void*. If you cut that out...
>>
>> ```
>> class Foo {
>> ~this() @nogc nothrow {}
>> }
>>
>> void main() @nogc nothrow {
>> scope auto foo = new Foo();
>> foo.__xdtor();
>> }
>> ```
>>
>> this works today.
>
> I thought the problem with this was that destructors aren't
> virtual, so if you write something like this:
> [...]
> ...then you end up calling Foo's destructor, but not Bar's.
> That's why rt_finalize uses TypeInfo to look up the destructor
> for the object's runtime type.
we can use custom destructors:
```d
class Foo {
~this() nothrow @nogc {}
void destroy() nothrow @nogc
{
__xdtor();
}
}
class Bar : Foo {
override void destroy()
{
super.destroy();
}
}
void main() {
Foo foo = new Bar();
foo.destroy();
}
```
I dont know why destructors are not virtual. This makes sense for
constructors as the correct instance size is required but not for
destructors.
More information about the Digitalmars-d-announce
mailing list