D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15765 - TypeInfo for C++ classes uses wrong vtbl
Summary: TypeInfo for C++ classes uses wrong vtbl
Status: RESOLVED DUPLICATE of issue 15813
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-05 12:38 UTC by Martin Nowak
Modified: 2020-02-19 05:23 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2016-03-05 12:38:41 UTC
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.
Comment 1 Mathias LANG 2020-02-19 05:23:03 UTC
Marking of duplicate of 15813 since this issue is the more "user-facing" bug.

*** This issue has been marked as a duplicate of issue 15813 ***