[Issue 15765] New: TypeInfo for C++ classes uses wrong vtbl

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Mar 5 04:38:41 PST 2016


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

          Issue ID: 15765
           Summary: TypeInfo for C++ classes uses wrong vtbl
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: code at dawg.eu

cat > bug.d << CODE
extern (C++) class RootObject
{
    bool equals(RootObject o)
    {
        return o is this;
    }

    int compare(RootObject)
    {
        assert(0);
    }

    void print()
    {
        assert(0, "Should not get called");
    }
}

void main()
{
    bool[RootObject] aa;
    aa[new RootObject] = true;
}
CODE
----
dmd -run bug
----

Because TypeInfo_Class casts every void* to a standard Object, it ends up
calling the wrong vtable entries for operations like getHash.

I think we need a dedicated TypeInfo_CppClass that is similar to
TypeInfo_Struct with it's xopEquals and xopHash in order to fix this bug.
C++ classes don't inherit from the common Object class, so those methods must
not exist.

--


More information about the Digitalmars-d-bugs mailing list