www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24139] New: 'this' corruption in extern(C++) dtor when

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

          Issue ID: 24139
           Summary: 'this' corruption in extern(C++) dtor when destructing
                    via TypeInfo_Struct
           Product: D
           Version: D2
          Hardware: x86
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

Iff. the struct itself has no `extern(C++)` linkage, but its destructor. E.g.,
the assertion in line 3 fails for 32-bit x86:
```
struct S1
{
    int x;
    extern(C++) ~this() { assert(&this == s1); }
}

extern(C++) struct S2
{
    int x;
    ~this() { assert(&this == s2); }
}

S1* s1;
S2* s2;

void main()
{
    s1 = new S1;
    s2 = new S2;

    typeid(s1).destroy(s1);
    typeid(s2).destroy(s2);
}
```

--
Sep 10 2023