-
-
Notifications
You must be signed in to change notification settings - Fork 657
fix Issue 22287 - ambiguous virtual function for extern(C++) under Wi… #13068
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,337 @@ | ||
| #include <assert.h> | ||
|
|
||
| class X | ||
| { | ||
| public: | ||
| virtual ~X(); | ||
| int i; | ||
| }; | ||
|
|
||
| X::~X() | ||
| { | ||
| } | ||
|
|
||
| class Y : public X | ||
| { | ||
| }; | ||
|
|
||
| class A | ||
| { | ||
| public: | ||
| virtual ~A(); | ||
| virtual int f1() const; | ||
|
|
||
| int i; | ||
| }; | ||
|
|
||
| class I | ||
| { | ||
| public: | ||
| virtual int f2() const = 0; | ||
| virtual X *f4() = 0; | ||
| }; | ||
|
|
||
| class B : public A, public I | ||
| { | ||
| public: | ||
| virtual int f1() const; | ||
| virtual int f2() const; | ||
| virtual int f3() const; | ||
| virtual X *f4(); | ||
| }; | ||
|
|
||
| class C : public B | ||
| { | ||
| public: | ||
| virtual int f1() const; | ||
| virtual int f2() const; | ||
| virtual int f3() const; | ||
| virtual Y *f4(); | ||
| }; | ||
|
|
||
| #ifdef _WIN32 | ||
| class D : public B | ||
| { | ||
| public: | ||
| virtual int f1() const; | ||
| virtual int f2() const; | ||
| virtual int f3() const; | ||
| virtual Y *f4(); | ||
| }; | ||
|
|
||
| class E : public B | ||
| { | ||
| public: | ||
| virtual int f1() const; | ||
| virtual int f2() const; | ||
| virtual int f3() const; | ||
| virtual Y *f4(); | ||
| }; | ||
| #endif | ||
|
|
||
| A::~A() | ||
| { | ||
| } | ||
|
|
||
| int A::f1() const | ||
| { | ||
| return i + 11; | ||
| } | ||
|
|
||
| int B::f1() const | ||
| { | ||
| return i + 21; | ||
| } | ||
|
|
||
| int B::f2() const | ||
| { | ||
| return i + 22; | ||
| } | ||
|
|
||
| int B::f3() const | ||
| { | ||
| return i + 23; | ||
| } | ||
|
|
||
| X *B::f4() | ||
| { | ||
| X *r = new X; | ||
| r->i = i + 24; | ||
| return r; | ||
| } | ||
|
|
||
| int C::f1() const | ||
| { | ||
| return i + 31; | ||
| } | ||
|
|
||
| int C::f2() const | ||
| { | ||
| return i + 32; | ||
| } | ||
|
|
||
| int C::f3() const | ||
| { | ||
| return i + 33; | ||
| } | ||
|
|
||
| Y *C::f4() | ||
| { | ||
| Y *r = new Y; | ||
| r->i = i + 34; | ||
| return r; | ||
| } | ||
|
|
||
| I *createIFromCPP(char type, int i) | ||
| { | ||
| switch (type) | ||
| { | ||
| case 'B': | ||
| { | ||
| B *b = new B(); | ||
| b->i = i; | ||
| return b; | ||
| } | ||
| case 'C': | ||
| { | ||
| C *c = new C(); | ||
| c->i = i; | ||
| return c; | ||
| } | ||
| #ifdef _WIN32 | ||
| case 'D': | ||
| { | ||
| D *d = new D(); | ||
| d->i = i; | ||
| return d; | ||
| } | ||
| case 'E': | ||
| { | ||
| E *e = new E(); | ||
| e->i = i; | ||
| return e; | ||
| } | ||
| #endif | ||
| default: | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| B *createBFromCPP(char type, int i) | ||
| { | ||
| switch (type) | ||
| { | ||
| case 'B': | ||
| { | ||
| B *b = new B(); | ||
| b->i = i; | ||
| return b; | ||
| } | ||
| case 'C': | ||
| { | ||
| C *c = new C(); | ||
| c->i = i; | ||
| return c; | ||
| } | ||
| #ifdef _WIN32 | ||
| case 'D': | ||
| { | ||
| D *d = new D(); | ||
| d->i = i; | ||
| return d; | ||
| } | ||
| case 'E': | ||
| { | ||
| E *e = new E(); | ||
| e->i = i; | ||
| return e; | ||
| } | ||
| #endif | ||
| default: | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| C *createCFromCPP(int i) | ||
| { | ||
| C *c = new C(); | ||
| c->i = i; | ||
| return c; | ||
| } | ||
|
|
||
| #ifdef _WIN32 | ||
| D *createDFromCPP(int i) | ||
| { | ||
| D *d = new D(); | ||
| d->i = i; | ||
| return d; | ||
| } | ||
|
|
||
| E *createEFromCPP(int i) | ||
| { | ||
| E *e = new E(); | ||
| e->i = i; | ||
| return e; | ||
| } | ||
| #endif | ||
|
|
||
| I *createIFromD(char type, int i); | ||
| B *createBFromD(char type, int i); | ||
| C *createCFromD(int i); | ||
| #ifdef _WIN32 | ||
| D *createDFromD(int i); | ||
| E *createEFromD(int i); | ||
| #endif | ||
|
|
||
| void runCPPTests() | ||
| { | ||
| { | ||
| B *b = new B(); | ||
| b->i = 100; | ||
| assert(b->f1() == 121); | ||
| assert(b->f2() == 122); | ||
| assert(b->f3() == 123); | ||
| assert(b->f4()->i == 124); | ||
| } | ||
| { | ||
| C *c = new C(); | ||
| c->i = 100; | ||
| assert(c->f1() == 131); | ||
| assert(c->f2() == 132); | ||
| assert(c->f3() == 133); | ||
| assert(c->f4()->i == 134); | ||
| } | ||
| #ifdef _WIN32 | ||
| { | ||
| D *d = new D(); | ||
| d->i = 100; | ||
| assert(d->f1() == 141); | ||
| assert(d->f2() == 142); | ||
| assert(d->f3() == 143); | ||
| assert(d->f4()->i == 144); | ||
| } | ||
| { | ||
| E *e = new E(); | ||
| e->i = 100; | ||
| assert(e->f1() == 151); | ||
| assert(e->f2() == 152); | ||
| assert(e->f3() == 153); | ||
| assert(e->f4()->i == 154); | ||
| } | ||
| #endif | ||
| { | ||
| I *i = createIFromD('B', 100); | ||
| assert(i->f2() == 122); | ||
| assert(i->f4()->i == 124); | ||
| } | ||
| { | ||
| I *i = createIFromD('C', 100); | ||
| assert(i->f2() == 132); | ||
| assert(i->f4()->i == 134); | ||
| } | ||
| #ifdef _WIN32 | ||
| { | ||
| I *i = createIFromD('D', 100); | ||
| assert(i->f2() == 142); | ||
| assert(i->f4()->i == 144); | ||
| } | ||
| { | ||
| I *i = createIFromD('E', 100); | ||
| assert(i->f2() == 152); | ||
| assert(i->f4()->i == 154); | ||
| } | ||
| #endif | ||
| { | ||
| B *b = createBFromD('B', 100); | ||
| assert(b->f1() == 121); | ||
| assert(b->f2() == 122); | ||
| assert(b->f3() == 123); | ||
| assert(b->f4()->i == 124); | ||
| } | ||
| { | ||
| B *b = createBFromD('C', 100); | ||
| assert(b->f1() == 131); | ||
| assert(b->f2() == 132); | ||
| assert(b->f3() == 133); | ||
| assert(b->f4()->i == 134); | ||
| } | ||
| #ifdef _WIN32 | ||
| { | ||
| B *b = createBFromD('D', 100); | ||
| assert(b->f1() == 141); | ||
| assert(b->f2() == 142); | ||
| assert(b->f3() == 143); | ||
| assert(b->f4()->i == 144); | ||
| } | ||
| { | ||
| B *b = createBFromD('E', 100); | ||
| assert(b->f1() == 151); | ||
| assert(b->f2() == 152); | ||
| assert(b->f3() == 153); | ||
| assert(b->f4()->i == 154); | ||
| } | ||
| #endif | ||
| { | ||
| C *c = createCFromD(100); | ||
| assert(c->f1() == 131); | ||
| assert(c->f2() == 132); | ||
| assert(c->f3() == 133); | ||
| assert(c->f4()->i == 134); | ||
| } | ||
| #ifdef _WIN32 | ||
| { | ||
| D *d = createDFromD(100); | ||
| assert(d->f1() == 141); | ||
| assert(d->f2() == 142); | ||
| assert(d->f3() == 143); | ||
| assert(d->f4()->i == 144); | ||
| } | ||
| { | ||
| E *e = createEFromD(100); | ||
| assert(e->f1() == 151); | ||
| assert(e->f2() == 152); | ||
| assert(e->f3() == 153); | ||
| assert(e->f4()->i == 154); | ||
| } | ||
| #endif | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While the result looks good, I wonder whether the explicit comparison of the type modifier is necessary (should be part of
Type.equalsAFAICT), but also why only an exact match is considered and not a covariant overload, tooThis seems a bit confusing as
seenInterfaceVirtualis reset for eachvtbl.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.
You are right, that it should also allow covariant functions. Currently they would still get the error. I will change that and extend the test.
The function searchVtbl is called for the current class and every base class. If multiple matching functions are found in a single call of searchVtbl, then seenInterfaceVirtual will be true for the second and the error message will be generated.