[Issue 14363] DMD should compile SDC test0165.d

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Mar 29 04:09:22 PDT 2015


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

--- Comment #4 from Kenji Hara <k.hara.pg at gmail.com> ---
Maybe SDC inserts a hidden field to access enclosing scope in each derived
classes?

void main() {
    uint x = 7;

    class A {
        int fieldA;
        auto foo() { return x; }
    }

    auto makeB(uint y) {
        class B : A {
            int fieldB;
            auto bar() { return foo() + y; }
        }

        return new B(5);
    }

    A a = new A();
    assert(a.foo() == 7);

    auto b = makeB(3);
    alias B = typeof(b);
    assert(b.bar() == 10);

    pragma(msg, A.fieldA.offsetof);
    pragma(msg, __traits(classInstanceSize, A));
    pragma(msg, B.fieldB.offsetof);
    pragma(msg, __traits(classInstanceSize, B));
}

If B.fieldB.offsetof + int.sizeof + (void*).sizeof <=
__traits(classInstanceSize, B), both B and A have their own hidden fields.

Note that it's intentionally disallowed by dmd. With dmd, implicitly insertion
of hidden field is limited at most once. At best, it's an incompatibility
between dmd and SDC.

--


More information about the Digitalmars-d-bugs mailing list