Skip to content

fix #23262 - [REG v2.113.0-beta.1] ICE when trying to cast a class instance to a C++ interface#23263

Open
rainers wants to merge 1 commit into
dlang:stablefrom
rainers:issue_23262
Open

fix #23262 - [REG v2.113.0-beta.1] ICE when trying to cast a class instance to a C++ interface#23263
rainers wants to merge 1 commit into
dlang:stablefrom
rainers:issue_23262

Conversation

@rainers

@rainers rainers commented Jun 14, 2026

Copy link
Copy Markdown
Member

no need to exclude C++ classes/interfaces from runtime cast target

…ss instance to a C++ interface

no need to exclude C++ classes/interfaces from runtime cast target
@dlang-bot

Copy link
Copy Markdown
Contributor

Thanks for your pull request, @rainers!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + dmd#23263"

int funCpp();
}

class class23262 : Object, iface23262

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does inhering from a D class and a C++ interface simultaneously even make sense?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I use it in Visual D for COM classes all the time. That's where I triggered the issue.

int offset;
if ((cdto.isBaseOf(cdfrom, &offset) && offset != ClassDeclaration.OFFSET_RUNTIME)
|| cdfrom.classKind == ClassKind.cpp || cdto.classKind == ClassKind.cpp)
|| cdfrom.classKind == ClassKind.cpp)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are needed as casting between D<->C++ classes results in a null result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are needed as casting between D<->C++ classes results in a null result.

Why is this necessary? The D class has full runtime typeinfo available, including C++ interfaces. Also, this used to work up to 2.112.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this with the latest GDC version I could easily get hold of (gdc-12), and it indeed returns null from the cast. It behaves differently than all the released versions of DMD and LDC that succeed doing the cast to the C++ interface, so I think it should rather be fixed in GDC, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants