[Issue 8366] Overriding const member function in conjunction with mutable overload causes a strange error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 13 17:45:20 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=8366



--- Comment #6 from Kenji Hara <k.hara.pg at gmail.com> 2013-01-13 17:45:09 PST ---
(In reply to comment #5)
> What's the state of this? I'm getting different error messages, such as:
> 
> Deprecation: class test.C use of object.Object.opEquals(Object o) hidden by C
> is deprecated. Use 'alias Object.opEquals opEquals;' to introduce base class
> overload set.
> 
> Is that ok?

No.

In 2.060 release, all Object class method signatures are reverted, so the
original code is not correct in current. More generic case is:

class B
{
    bool foo(in Object o) const { return true; }
}
class C : B
{
    bool foo(in Object o)       { return true; }   // line 10
  override
    bool foo(in Object o) const { return false; }  // line 12
}
void main()
{
          C mc = new C();
    const C cc = new C();
          B mb  = mc;
    const B cb  = cc;
    assert(mc.foo(null) == true);
    assert(cc.foo(null) == false);
    assert(mb.foo(null) == false);
    assert(cb.foo(null) == false);
}

This code should compile but outputs:
---
test.d(10): Deprecation: overriding base class function without using override
attribute is deprecated (test.C.foo overrides test.B.foo)
test.d(12): Error: function test.C.foo multiple overrides of same function

Mutable foo in class C is incorrectly overrides const foo in class B. That is
the bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list