[Issue 22832] New: Can't destroy class with overloaded opCast
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 1 17:31:02 UTC 2022
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 at puremagic.com
Reporter: snarwin+bugzilla at 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.
--
More information about the Digitalmars-d-bugs
mailing list