[Issue 15425] std.traits.hasIndirections fails to recognize nested structs

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 31 07:58:22 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=15425

--- Comment #2 from Marc Schütz <schuetzm at gmx.net> ---
(In reply to RazvanN from comment #1)
> Maybe I am getting this wrong, but both S1 and S2 are free of indirections
> for as far as I can tell. Even if the sizeof includes the context pointer,
> it is not a user defined part of the struct.
> 
> hasIndirections does the following for structs:
> 
> static if (is(T == struct) || is(T == union))
>     enum hasIndirections = anySatisfy!(.hasIndirections, FieldTypeTuple!T);
> 
> As you can see, all the field types are tested (the context pointer is not
> an actual field of the struct), so in my opinion the output of your program
> is correct.

hasIndirections is used (among other things) to check whether a memory
allocation needs to be registered with the GC (e.g. in RefCounted), or whether
an object can be safely sent to another thread (e.g. hasUnsharedAliasing). For
these purposes, it is crucial that it checks _all_ indirections, not just the
explicitly declared ones.

In std.traits, there is a whole bunch of helper traits like hasRawAliasing,
hasRawUnsharedAliasing, hasAliasing with partially overlapping functionality. I
don't know what each one is supposed to be used for; maybe hasIndirections
actually does what it should. But if so, then it's clearly used wrongly in
other places (e.g. RefCounted).

--


More information about the Digitalmars-d-bugs mailing list