#dbugfix 17592

12345swordy alexanderheistermann at gmail.com
Wed Mar 21 19:21:15 UTC 2018


On Wednesday, 21 March 2018 at 14:04:58 UTC, Adam D. Ruppe wrote:
> 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.

That seems to be it's own separate problem, as it involves 
generating dynamic types at run-time, which it needs run-time 
equivalent of attribute checking. My example assumes that the 
classes created are static types not dynamic types. Besides I do 
not like implied conversions when it comes classes, as I believe 
it is a horrible idea.


More information about the Digitalmars-d mailing list