Bug 13867 – Overriding a method from an extern(C++) interface requires extern(C++) on the method definition

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-12-15T21:43:00Z
Last change time
2016-10-01T11:46:47Z
Keywords
C++, diagnostic, pull
Assigned to
nobody
Creator
redballoon36

Comments

Comment #0 by redballoon36 — 2014-12-15T21:43:38Z
Code example: extern(C++) interface INTERFACE { void aMethod(); } class CLASS : INTERFACE { override void aMethod() { } } With this code, dmd 2.066 gives the error: Function CLASS.aMethod does not override any function, did you mean to override 'INTERFACE.aMethod'? Changing the definition to: extern(C++) override void aMethod() { } satisfies the requirements for overload. Immediate problem: The error message does not provide sufficient information to identify the issue. However, I think it would be better for the method in CLASS to override the method in INTERFACE without the extern(C++) attribute. There is no way for the call-site to distinguish between a method that is extern(C++) vs. simply extern(D). Though I don't know how to make it work if CLASS also implements a normal D interface that also has aMethod, e.g. interface DINTERFACE { void aMethod(); } class CLASS : INTERFACE, DINTERFACE { override void aMethod() { } } So the only fix I see right now is to improve the diagnostic message.
Comment #1 by nicolas.jinchereau — 2015-04-26T16:26:10Z
+1 for allowing extern(C++) interface members to be implemented without specifying the linkage. In fact, I believe it is a bug for this not to be the case. Consider this example: interface A { void foo(); } extern(C++) interface B { void foo(); } class Test : A, B { void foo() { } extern(C++) void foo(){} } void main() { Test test = new Test(); test.foo(); // error: ambiguous call to 'foo' } I believe the fact that the above example would compile fine if 'extern(C++)' was removed reinforces this point. I think this should be changed to a bug.
Comment #2 by github-bugzilla — 2016-05-06T21:52:02Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/da397409004e3abb434ed2cdcfb0ff8615d28ad9 fix Issue 13867 - Improve error message when overriding an extern(C++) interface https://github.com/dlang/dmd/commit/b862dab3ba938f4302192947de241b2ac024f95e Merge pull request #5732 from lionello/fix13867 fix Issue 13867 - Improve error message when overriding an extern(C++) interface
Comment #3 by github-bugzilla — 2016-10-01T11:46:47Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/da397409004e3abb434ed2cdcfb0ff8615d28ad9 fix Issue 13867 - Improve error message when overriding an extern(C++) interface https://github.com/dlang/dmd/commit/b862dab3ba938f4302192947de241b2ac024f95e Merge pull request #5732 from lionello/fix13867