Bug 22832 – Can't destroy class with overloaded opCast
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-01T17:31:02Z
Last change time
2022-03-02T14:03:47Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus
Comments
Comment #0 by snarwin+bugzilla — 2022-03-01T17:31:02Z
As of DMD 2.098.1, the following program fails to compile:
---
struct A {}
class B {
A opCast(T : A)() {
return A();
}
}
void main() {
destroy(B.init);
}
---
The compiler gives the following error message:
---
/dlang/dmd/linux/bin64/../../src/druntime/import/object.d(4209): Error: template instance `opCast!(void*)` does not match template declaration `opCast(T : A)()`
onlineapp.d(8): Error: template instance `object.destroy!(true, B)` error instantiating
---
This happens because destroy attempts to cast the class reference to a void* in order to pass it to rt_finalize. The presence of an opCast overload causes this cast to fail at compile time.
Comment #1 by dlang-bot — 2022-03-01T17:54:47Z
@pbackus created dlang/druntime pull request #3766 "Fix issue 22832 - Can't destroy class with overloaded opCast" fixing this issue:
- Fix issue 22832 - Can't destroy class with overloaded opCast
https://github.com/dlang/druntime/pull/3766
Comment #2 by dlang-bot — 2022-03-02T14:03:47Z
dlang/druntime pull request #3766 "Fix issue 22832 - Can't destroy class with overloaded opCast" was merged into master:
- 6f2136cb9ff7c2877bb380ab61251daed1734e78 by Paul Backus:
Fix issue 22832 - Can't destroy class with overloaded opCast
https://github.com/dlang/druntime/pull/3766