Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

Per Nordlöw per.nordlow at gmail.com
Wed May 9 14:07:37 UTC 2018


Why (on earth) does

     struct S
     {
         @disable this(this);
         int* _ptr;
     }
     pragma(msg, typeof(S.tupleof));

prints

(int*, void*)

when

     struct S
     {
         int* _ptr;
     }
     pragma(msg, typeof(S.tupleof));

prints

(int*)

?!!!

This prevents the trait `mustAddGCRangeOfStructOrUnion` [1] from 
detecting when a container with manual memory management doesn't 
have to be scanned by the GC as in, for instance,

     enum NoGc;
     struct S
     {
         @disable this(this); // disable S postlib
         @NoGc int* _ptr;
     }
     static assert(!mustAddGCRangeOfStructOrUnion!S); // is false 
when postblit of `S` is disabled

[1] 
https://github.com/nordlow/phobos-next/blob/master/src/gc_traits.d#L81


More information about the Digitalmars-d-learn mailing list