-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For COM interfaces T and U, if T is derived from U, implement From<T> for U #2764
Comments
There is, indeed. In COM Theory™, reference counts are strictly per interface. When transmuting from one (owning) representation into a different (owning) representation, In practice, this frequently pans out, even if wrong. While I haven't made up my mind whether 2024 is going to be the year when I stop giving a damn, I'll proactively suggest not introducing this. This isn't to say that ergonomics for upcasting COM interfaces couldn't be improved. It's just that—this time—the simple solution won't do. I'm confident some sharp minds will review this and procure a workable solution. Happy New Year, regardless! |
The move constructor for Microsoft’s own |
Yes, that's the same bug. You'd need to instantiate a COM object that implements a tear-off interface to exercise the error mode. Raymond Chen published several blog posts on this topic:
Apparently, tear-offs are a real thing. |
The issue with tearoffs/aggregates doesn't apply here since the The main reason I'd be reluctant to add the suggestion is that it would add a ton of (expanded) code to the |
This should do the trick: #2779 |
Suggestion
The
interface_hierarchy
macro and theCanInto
trait enable upcasting of COM interfaces, but this only appears to be used for arguments to Windows API functions (through the undocumentedIntoParam
trait).It would be useful to additionally support upcasting of COM interfaces directly. This is always safe and infallible, so
ComInterface::cast
is not suitable. Example code that would compile with this change:Note that this would be a zero-cost conversion; no clone or call to
QueryInterface
necessary.I think the implementation would be as simple as having
interface_hierarchy
generate transmutingFrom
impls: 9057d9e but maybe there is more to it that I am not aware of.The text was updated successfully, but these errors were encountered: