[Issue 15934] New: Non-virtual super class member function call ignores 'this' type qualifier

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Apr 17 07:53:52 PDT 2016


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

          Issue ID: 15934
           Summary: Non-virtual super class member function call ignores
                    'this' type qualifier
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: k.hara.pg at gmail.com

Test case:

class B
{
    int foo()       { return 1; }
    int foo() const { return 2; }
}

class C : B
{
    override int foo()       { return 3; }
    override int foo() const { return 4; }

    void test1()
    {
        assert(this.foo() == 3);
        assert(     foo() == 3);
        assert(this.B.foo() == 1);
        assert(     B.foo() == 1);
    }

    void test2() const
    {
        assert(this.foo() == 4);
        assert(     foo() == 4);
        assert(this.B.foo() == 2);  // fail, 1 is incorrectly returned
        assert(     B.foo() == 2);  // fail, 1 is incorrectly returned
    }
}

void test()
{
    auto c = new C();
    c.test1();
    c.test2();
}

--


More information about the Digitalmars-d-bugs mailing list