Reduced example:
struct S(T) {
invariant (&this != null);
~this() {
fun();
}
void fun() {
int i;
}
void opEquals(T)(T t) if (false) { }
}
unittest {
S!int a;
}
As the changed summary indicates, `this` is null in the invariant. It is not null in ~this() or in fun().
opEquals() is of course never instantiated, but it needs to be there - it needs to have a template constraint, and it needs to take at least one argument, which needs to have a name, and needs to be of the type in the template parameter list.
The invariant is called after fun(), so fun() needs to be there. It can't be empty, but it obviously doesn't need to do anything sensible.
Comment #2 by razvan.nitu1305 — 2023-04-18T11:08:56Z
I cannot reproduce the segfault.
Compiling and running both the original code snippet and the reduced one result in successful compilation and run.