Bug 23946 – specifications state that "there can only be one destructor" which can be confusing because of mixin templates
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-05-30T10:37:57Z
Last change time
2023-06-12T14:18:32Z
Keywords
pull
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2023-05-30T10:37:57Z
ยง2 of https://dlang.org/spec/class.html#destructors states that "There can be only one destructor per class, the destructor does not have any parameters, and has no attributes. It is always virtual."
However this creates confusion as mixin templates are allowed to introduce a destructor.
eg.
```
import std;
mixin template AddNewDtor()
{
~this()
{
writeln("Mixin dtor");
}
}
class Foo
{
~this()
{
writeln("Class dtor");
}
mixin AddNewDtor;
}
void main()
{
{
auto s = scoped!Foo;
// prints `Mixin dtor`
// prints `Class dtor`
}
}
```
The specifications should be more clear. While some might know that there are the internal __dtor and __xdtor functions, the specs should mention that
"destructors introduced by mixin templates are implicitly called by the main destructor and does not represent a real destructor" in https://dlang.org/spec/template-mixin.html.
That's just a suggestion, any other solution that would prevent a possible confusion for new comers is welcome.
See NG thread : https://forum.dlang.org/post/[email protected]
Comment #1 by dlang-bot — 2023-06-10T11:34:18Z
@ntrel created dlang/dlang.org pull request #3636 "Fix Issue 23946 - spec states "there can only be one destructor"" fixing this issue:
- Fix Issue 23946 - specifications state that "there can only be one destructor"
...which can be confusing because of mixin templates
https://github.com/dlang/dlang.org/pull/3636
Comment #2 by dlang-bot — 2023-06-12T14:18:32Z
dlang/dlang.org pull request #3636 "Fix Issue 23946 - spec states "there can only be one destructor"" was merged into master:
- b70588595470372436c3f9b10ed91cb2cd3dc635 by Nick Treleaven:
Fix Issue 23946 - specifications state that "there can only be one destructor"
...which can be confusing because of mixin templates
https://github.com/dlang/dlang.org/pull/3636