www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13867] New: Overriding a method from an extern(C++) interface

https://issues.dlang.org/show_bug.cgi?id=13867

          Issue ID: 13867
           Summary: Overriding a method from an extern(C++) interface
                    requires extern(C++) on the method definition
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: redballoon36 gmail.com

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.

--
Dec 15 2014