www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22832] New: Can't destroy class with overloaded opCast


          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() {

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

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