```
module current;
class C
{
// needed for `S` to get a `__xtoHash`
int opCmp(const C rhs) const { return 1; }
}
struct S
{
C c;
union
{
string str;
S[] ss;
}
ulong[10_000] large;
}
void main()
{
S s = {str: "wsdpfijsdpfijspfklmxcö,,msdfkjsmndfpösdmnfpoisdmfüosijfposidj"};
const h = typeid(S).getHash(&s);
}
```
The code above segfaults with DMD v2.097.1, with the following backtrace:
#0 0x00005555555a9da5 in object.TypeInfo_Class.getHash(scope const(void*)) const ()
#1 0x00005555555aa6e3 in object.TypeInfo_Const.getHash(scope const(void*)) const ()
#2 0x00005555555a8d1f in _D7current1S9__xtoHashFNbNeKxSQBcQxZm ()
#3 0x00005555555aa38e in object.TypeInfo_Struct.getHash(scope const(void*)) const ()
#4 0x00005555555aa6e3 in object.TypeInfo_Const.getHash(scope const(void*)) const ()
#5 0x00005555555ab24c in object.getArrayHash(scope const(TypeInfo), scope const(void*), const(ulong)) ()
#6 0x00005555555a92c4 in object.TypeInfo_Array.getHash(scope const(void*)) const ()
#7 0x00005555555aa6e3 in object.TypeInfo_Const.getHash(scope const(void*)) const ()
#8 0x00005555555a8d6c in _D7current1S9__xtoHashFNbNeKxSQBcQxZm ()
#9 0x00005555555aa38e in object.TypeInfo_Struct.getHash(scope const(void*)) const ()
#10 0x00005555555a8e17 in D main ()
I guess it's trying to compute the hashes of *all* members, so both `str` and `ss`, with `ss` likely representing invalid memory if the `str` member with way smaller element size (char vs. S) was set.
Comment #1 by robert.schadek — 2024-12-13T19:17:48Z