On Wednesday, 21 March 2018 at 13:39:28 UTC, 12345swordy wrote:
You can simply check the .dtor symbols at compile time to see
if every .dtor symbol from child to root have a .dtor that have
the @nogc attribute
In Simen's example, the child information is not available at
compile time. This line here:
A a = new B();
discards the static type. The compiler could probably cheat and
figure it out anyway in this example, but suppose:
---
class A {
@nogc ~this() {}
}
class B : A {
~this() {}
}
class C : A {
@nogc ~this() {}
}
A build(string name) {
if(name == "B") return new B();
else return new C();
}
void main() {
A a = build(readln());
destroy(a);
}
---
This is very clearly a runtime decision: whether it is B or C is
determined by user input. But B's dtor is not @nogc... and
there's thus no way to tell for sure if destroy(a) is or not,
since it will call the child class based on the runtime decision.
so it is impossible for the compiler to know which child class is
actually called until runtime... too late for a compile-time nogc
check.