Bug 19258 – Cannot @disable ~this()

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-09-22T03:27:13Z
Last change time
2019-10-20T15:15:05Z
Keywords
C++, rejects-valid
Assigned to
No Owner
Creator
Илья Ярошенко

Comments

Comment #0 by ilyayaroshenko — 2018-09-22T03:27:13Z
Fails: struct S { this(int i){} @disable ~this(){} } extern(C++) S foo() { return S(3); } It should compiles because destructor is not called in `foo`.
Comment #1 by ilyayaroshenko — 2018-09-22T03:28:04Z
required for integration with C++
Comment #2 by ilyayaroshenko — 2018-09-22T03:29:14Z
btw, extern(C++) can be skipped, the issue is valid for extern(D) as well
Comment #3 by iamthewilsonator — 2018-09-28T09:16:57Z
I'm not sure what the desired effect of @disabling the destructor is supposed to achieve? If this is for C++ integration either: a) don't declare it or b) if is required to consume a viable slot declare a dummy function.
Comment #4 by ilyayaroshenko — 2018-09-30T16:05:53Z
(In reply to Nicholas Wilson from comment #3) > I'm not sure what the desired effect of @disabling the destructor is > supposed to achieve? If this is for C++ integration either: a) don't declare > it or b) if is required to consume a viable slot declare a dummy function. The reason is to be sure that a D compiler does not compile ~this at all.
Comment #5 by iamthewilsonator — 2018-10-01T01:08:01Z
For structs if no destructor is given then no destructor is compiled. struct S { this(int i){} } extern(C++) S foo() { return S(3); } void main() { import std.traits; import std.stdio; writeln(__traits(allMembers,S)); // Prints: __ctor } For classes, inheritance is involved so you can't disable it anyway.
Comment #6 by dlang-bugzilla — 2019-10-20T15:15:05Z
The struct might have other members with destructors. It would be useful to prevent their destructors from being called, so this issue seems valid to me.