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()'
Comment #1 by kinke — 2022-05-24T20:13:35Z
After giving it a little thought, I agree. The alternative would probably mean special-casing in dtoh (.h generation) and C++ mangling, and that doesn't seem too worthwhile to me.
Comment #2 by tim.dlang — 2022-05-24T20:25:18Z
This is similar to issue 22351.
Comment #3 by ibuclaw — 2022-05-25T08:45:59Z
(In reply to Tim from comment #2)
> This is similar to issue 22351.
Excellent, looks like fixing this issue fixes the other as well.
Comment #4 by dlang-bot — 2022-05-25T12:33:55Z
@ibuclaw created dlang/dmd pull request #14169 "fix Issue 22351 - extern(C++) function contravariant in D, but not C++" fixing this issue:
- fix Issue 23135 - Covariance rules for C++ member functions mismatch D
https://github.com/dlang/dmd/pull/14169
Comment #5 by dlang-bot — 2022-05-27T01:15:47Z
dlang/dmd pull request #14169 "fix Issue 22351 - extern(C++) function contravariant in D, but not C++" was merged into master:
- 121fd73a1f8ebd6d563430d214507c436b885c32 by Iain Buclaw:
fix Issue 23135 - Covariance rules for C++ member functions mismatch D
https://github.com/dlang/dmd/pull/14169