Attributes not propagating to objects via typeinfo?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 13 09:05:19 PDT 2015


On 8/13/15 11:59 AM, Steven Schveighoffer wrote:

> That is definitely a bug. It's because typeid is looking up the derived
> type via the vtable, but the compiler should rewrap it with 'shared'
> afterwards.

Actually, now that I think about it, I'm not sure how the compiler can 
figure this out.

There would have to be a way to construct a TypeInfo_Shared at runtime, 
which the compiler shouldn't be doing. Alternatively, it could 
proactively create a TypeInfo_Shared (and all the other flavors) for 
each class type in the runtime, and then look it up using some hash 
mechanism.

This likely isn't fixable.

What you CAN do, however, is:

typeid(typeof(c))

Which should get the *static* type (and that should be TypeInfo_Shared 
in both struct and class instances).

So likely this is not a bug, or at the best, a wontfix.

-Steve


More information about the Digitalmars-d-learn mailing list