www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15765] New: TypeInfo for C++ classes uses wrong vtbl


          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 puremagic.com
          Reporter: code dawg.eu

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

    int compare(RootObject)

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

void main()
    bool[RootObject] aa;
    aa[new RootObject] = true;
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.

Mar 05 2016