digitalmars.D.bugs - [Issue 22832] New: Can't destroy class with overloaded opCast
- d-bugmail puremagic.com (37/37) Mar 01 2022 https://issues.dlang.org/show_bug.cgi?id=22832
https://issues.dlang.org/show_bug.cgi?id=22832 Issue ID: 22832 Summary: Can't destroy class with overloaded opCast Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: druntime Assignee: nobody puremagic.com Reporter: snarwin+bugzilla gmail.com 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. --
Mar 01 2022