-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
fix Issue 15579 - extern(C++) interfaces/multiple-inheritance #5361
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -982,6 +982,61 @@ void testeh3() | |
| } | ||
| } | ||
|
|
||
| /****************************************/ | ||
| // 15579 | ||
|
|
||
| extern (C++) | ||
| { | ||
| class Base | ||
| { | ||
| //~this() {} | ||
| void based() { } | ||
| ubyte x = 4; | ||
| } | ||
|
|
||
| interface Interface | ||
| { | ||
| int MethodCPP(); | ||
| int MethodD(); | ||
| } | ||
|
|
||
| class Derived : Base, Interface | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, D compiler doesn't add pointer to the typeid(Derived) into its vtbl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's beyond the scope of this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I'll try to do it later. |
||
| { | ||
| short y = 5; | ||
| int MethodCPP(); | ||
| int MethodD() { return 3; } | ||
| } | ||
|
|
||
| Derived cppfoo(Derived); | ||
| Interface cppfooi(Interface); | ||
| } | ||
|
|
||
| void test15579() | ||
| { | ||
| Derived d = new Derived(); | ||
| assert(d.x == 4); | ||
| assert(d.y == 5); | ||
| assert(d.MethodD() == 3); | ||
| assert(d.MethodCPP() == 30); | ||
|
|
||
| d = cppfoo(d); | ||
| assert(d.x == 7); | ||
| assert(d.y == 8); | ||
| version (Win64) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's just for the moment until I get it fixed. |
||
| { | ||
| // needs more work | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this suggest this is not yet compatible with MSC-Win64? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Walter wrote that he want implement MSC part it another PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's right. Win32 and Posix systems work fine, but VC++ is doing something different with the vtbl[]s. Grrr. The current fix is not wrong, it is still necessary for Win64. It's just that that particular test case still fails (before the PR, all of them failed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'll wait for the next patch to try it out. |
||
| } | ||
| else | ||
| { | ||
| assert(d.MethodD() == 3); | ||
| assert(d.MethodCPP() == 30); | ||
| } | ||
| printf("d = %p, i = %p\n", d, cast(Interface)d); | ||
| Interface i = cppfooi(d); | ||
| assert(i.MethodD() == 3); | ||
| assert(i.MethodCPP() == 30); | ||
| } | ||
|
|
||
| /****************************************/ | ||
|
|
||
| void main() | ||
|
|
@@ -1018,6 +1073,7 @@ void main() | |
| testeh(); | ||
| testeh2(); | ||
| testeh3(); | ||
| test15579(); | ||
|
|
||
| printf("Success\n"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -578,4 +578,66 @@ void throwle() | |
| #endif | ||
|
|
||
| /******************************************/ | ||
| // 15579 | ||
|
|
||
| class Base | ||
| { | ||
| public: | ||
| //virtual ~Base() {} | ||
| virtual void base(); | ||
| unsigned char x; | ||
| }; | ||
|
|
||
| class Interface | ||
| { | ||
| public: | ||
| virtual int MethodCPP() = 0; | ||
| virtual int MethodD() = 0; | ||
| }; | ||
|
|
||
| class Derived : public Base, public Interface | ||
| { | ||
| public: | ||
| Derived(); | ||
| short y; | ||
| int MethodCPP(); | ||
| #if _WIN32 || _WIN64 | ||
| int MethodD(); | ||
| #else | ||
| int MethodD() { return 3; } // need def or vtbl[] is not generated | ||
| #endif | ||
| }; | ||
|
|
||
| void Base::base() { } | ||
| int Derived::MethodCPP() { return 30; } | ||
| Derived::Derived() { } | ||
|
|
||
|
|
||
| Derived *cppfoo(Derived *d) | ||
| { | ||
| assert(d->x == 4); | ||
| assert(d->y == 5); | ||
| assert(d->MethodD() == 3); | ||
| assert(d->MethodCPP() == 30); | ||
|
|
||
| d = new Derived(); | ||
| d->x = 7; | ||
| d->y = 8; | ||
| assert(d->MethodD() == 3); | ||
| assert(d->MethodCPP() == 30); | ||
| return d; | ||
| } | ||
|
|
||
| Interface *cppfooi(Interface *i) | ||
| { | ||
| printf("i = %p\n", i); | ||
| assert(i->MethodD() == 3); | ||
| assert(i->MethodCPP() == 30); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if we write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will fail because D does not generate C++ typeinfo. |
||
|
|
||
| Derived *d = new Derived(); | ||
| printf("d = %p, i = %p\n", d, (Interface *)d); | ||
| return d; | ||
| } | ||
|
|
||
| /******************************************/ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change affects extern (D) class layout, not only for
extern (C++). Test case is:Is this intentional? If so, we should update ABI page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a regression issue: https://issues.dlang.org/show_bug.cgi?id=15618