www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23135] New: Covariance rules for C++ member functions

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

          Issue ID: 23135
           Summary: Covariance rules for C++ member functions mismatch D
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

C++ does not allow having a const method to override a mutable one, for best
compatibility with C++11 we shouldn't allow this either in extern(C++) code.

---
extern(C++) class foo
{
    void func() { }
}

extern(C++) final class bar : foo
{
    override void func() const { }
}
---
class foo
{
public:
    virtual void func();
};

class bar final : public foo
{
public:
    void func() override;
};

int main()
{
  bar b;
  b.func();
}
---

Results in:
---
error: cxxtest.cc:(.text+0x2e): undefined reference to `bar::func()'

--
May 24 2022